题目内容

The following loop displays _______________.for (int i = 1; i <= 10; i++) {System.out.print(i + " ");i++;}

A. 1 2 3 4 5 6 7 8 9
B. 1 2 3 4 5
C. 2 4 6 8 10
D. 1 3 5 7 9

查看答案
更多问题

Is the following loop correct?for (; ; );

A. No
B. Yes

What is the output of the following fragment?for (int i = 0; i < 15; i++) {if (i % 4 == 1)System.out.print(i + " "); }

A. 1 5 9 13 16
B. 1 4 8 12
C. 1 3 5 7 9 11 13 15
D. 1 5 9 13

Analyze the following statement:double sum = 0;for (double d = 0; d < 10;) {d += 0.1;sum += sum + d;}

A. The program has a compile error because the adjustment is missing in the for loop.
B. The program compiles and runs fine.
C. The program has a compile error because the control variable in the for loop cannot be of the double type.
D. The program runs in an infinite loop because d<10 would always be true.

Suppose the input for number is 9. What is the output from running the following program?import javA.util.Scanner;public class Test {public static void main(String[] args) {Scanner input = new Scanner(System.in);System.out.print("Enter an integer: ");int number = input.nextInt(); int i; boolean isPrime = true;for (i = 2; i < number && isPrime; i++) {if (number % i == 0) {isPrime = false;}} System.out.println("i is " + i); if (isPrime)System.out.println(number + " is prime");elseSystem.out.println(number + " is not prime"); }}

A. i is 3 followed by 9 is not prime
B. i is 4 followed by 9 is prime
C. i is 4 followed by 9 is not prime
D. i is 3 followed by 9 is prime

答案查题题库