Q11: What is the output of the following loop if the user input is: 10, 20, 30, 35, 40, -1
System.out.println("Enter a negative score to signal the end of the input.");
int total = 0, count = 0;
int score;
System.out.println("Score: ");
Scanner get = new Scanner(System.in);
score= get.nextInt();
while (score >= 0) {
count++;
total += score;
System.out.print("Score: ");
score = get.nextInt();
}
System.out.println( (total * 1.0) / count);
27.0
27
22.5
22
Compilation error
2.
Q12: What is the output of the following loop if the user input is: 10, 20, 30, 35, 40, -1
System.out.println("Enter a negative score to signal the end of the input.");
int total = 0, count = 0;
int score;
System.out.println("Score: ");
Scanner get = new Scanner(System.in);
score= get.nextInt();
while (score >= 0) {
System.out.print("Score: ");
score = get.nextInt();
count++;
total += score;
}
System.out.println( (total * 1.0) / count);
27.0
22.5
24.8
20.666667
Compilation error
3.
Q13: What is the output of the following loop if the user input is: 10, 20, 30, 35, 40, -1
System.out.println("Enter a negative score to signal the end of the input.");
int total = 0, count = 0;
int score;
System.out.println("Score: ");
Scanner get = new Scanner(System.in);
score= get.nextInt();
while (score >= 0) {
total += score;
System.out.print("Score: ");
score = get.nextInt();
count++;
}
System.out.println( (total * 1.0) / count);