The following code fragment repeatedly reads a number from the user until a numb
ID: 3631472 • Letter: T
Question
The following code fragment repeatedly reads a number from the user until a number greater than 10 is entered.Scanner console = new Scanner(System.in);
int num;
do {
System.out.print("Enter a number: ");
num = console.nextInt();
} while (num <= 10);
(Note: to execute this in the Interactions Pane, you will first need to enter the following command: import java.util.*;.)
What loop condition would be needed to make the loop repeat until the user enters a number greater than 10 that is also even? (1 point)
What loop condition would be needed to make the loop repeat until the user enters a number that is between 10 and 20, exclusive -- i.e, greater than 10 and less than 20? (1 point)
What loop condition would be needed to make the loop repeat until the user enters either 5 or 10? (1 point)
What loop condition would be needed to make the loop repeat until the user enters a two-digit number in which both digits are the same (e.g., a number like 11 or 55). You should not include all possible numbers of this type in your condition. Rather, part of your loop condition should be based on computations that extract the two digits of the number. (1 point)
The code fragment below uses a boolean flag named isValid to keep track of whether a valid input has been entered by the user. Fill in the blanks to make this fragment equivalent to the original version (i.e., the loop should repeat until the user enters a number that is greater than 10). (2 points)
Scanner console = new Scanner(System.in);
int num;
boolean validInput = _________;
while (!validInput) {
System.out.print("Enter a number: ");
num = console.nextInt();
validInput = _____________;
}
(Note: if you are running this in the Interactions Pane and you have already run the original version, you should omit the first two lines -- because the variables console and num will have already been declared.)
Explanation / Answer
please rate - thanks
The following code fragment repeatedly reads a number from the user until a number greater than 10 is entered.
Scanner console = new Scanner(System.in);
int num;
do {
System.out.print("Enter a number: ");
num = console.nextInt();
} while (num <= 10);
(Note: to execute this in the Interactions Pane, you will first need to enter the following command: import java.util.*;.)
What loop condition would be needed to make the loop repeat until the user enters a number greater than 10 that is also even? (1 point) while (!(num > 10 &&num%2==0));
What loop condition would be needed to make the loop repeat until the user enters a number that is between 10 and 20, exclusive -- i.e, greater than 10 and less than 20? (1 point)
while(num<=10||num>=20);
What loop condition would be needed to make the loop repeat until the user enters either 5 or 10? (1 point)
while(num!=5&&num!=10);
What loop condition would be needed to make the loop repeat until the user enters a two-digit number in which both digits are the same (e.g., a number like 11 or 55). You should not include all possible numbers of this type in your condition. Rather, part of your loop condition should be based on computations that extract the two digits of the number. (1 point) while(!(num/10==num%10));
The code fragment below uses a boolean flag named isValid to keep track of whether a valid input has been entered by the user. Fill in the blanks to make this fragment equivalent to the original version (i.e., the loop should repeat until the user enters a number that is greater than 10). (2 points)
Scanner console = new Scanner(System.in);
int num;
boolean validInput = false;
while (!validInput) {
System.out.print("Enter a number: ");
num = console.nextInt();
validInput =num>10;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.