Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Jump to level 1 First, read the first integer from input. Then, read the remaining integers while the integers are in the range - 5
Jump to level
First, read the first integer from input. Then, read the remaining integers while the integers are in the range to both inclusive.
For each integer read that is in the given range, output the integer followed by is accepted". Then, output the integer read that
causes the reading to stop followed by is rejected". End each output with a newline.
Ex: If the input is then the output is:
is accepted
is rejected
public class CountRead
public static void mainString args
Scanner scnr new Scanner
System.in;
int inputNumber;
inputNumber scnr nextInt ;
while inputNumber && inputNumber
if inputNumber && inputNumber
System.out.printlninputNumber is accepted";
else
System.out.printlninputNumber is rejected";
inputNumber scnrnextInt ;
A while loop reads integers from input until an integer is read that is not in the range to both inclusive. If an integer is in the
given range, the integer is output, followed by is accepted". Otherwise, the while loop terminates and the final output is the last
integer read from input, followed by is rejected". Each output ends with a newline.
Ex: For input :
is in the given range, so is accepted" is output.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started