Big Java Binder Early Objects

Computing

Quiz 6 :

Loops

Quiz 6 :

Loops

Question Type
search
arrow
The code snippet below checks whether a given number is a prime number. What will be the result of executing it? public static void main(String[] args) { Int j = 2; Int result = 0; Int number = 0; Scanner reader = new Scanner(System.in); System.out.println("Please enter a number: "); Number = reader.nextInt(); While (j <= number / 2) // better is while (j * j <= number) { If (number % j == 0) { Result = 1; } J++; } If (result == 1) { System.out.println("Number: " + number + " is Not Prime."); } Else { System.out.println("Number: " + number + " is Prime. "); } }
Free
Multiple Choice
Answer:

Answer:

B

Tags
Choose question tag
close menu
arrow
What output does this while loop generate? j = 6; While (j > 0) { System.out.print(j + ", "); J--; }
Free
Multiple Choice
Answer:

Answer:

C

Tags
Choose question tag
close menu
arrow
How many times does the code snippet below display "Hello"? Int i = 0; While (i != 15) { System.out.println("Hello"); I++; }
Free
Multiple Choice
Answer:

Answer:

C

Tags
Choose question tag
close menu
arrow
What is the output of the following code fragment? Int i = 1; Int sum = 0; While (i <= 15) { Sum = sum + i; I++; } System.out.println("The value of sum is " + sum);
Multiple Choice
Answer:
Tags
Choose question tag
close menu
arrow
What is the output of the following code snippet? Int i = 1; While (i <= 10) { System.out.println("Inside the while loop"); I = i + 10; }
Multiple Choice
Answer:
Tags
Choose question tag
close menu
arrow
What is the output of the following code snippet? Int i = 1; While (i < 20) { System.out.print(i + " "); I = i + 2; If (i == 15) { I = 19; } }
Multiple Choice
Answer:
Tags
Choose question tag
close menu
arrow
How many times does the following code fragment display "Hi"? Int i = 10; While (i >= 0) { System.out.println("Hi"); I--; }
Multiple Choice
Answer:
Tags
Choose question tag
close menu
arrow
What are the values of i and j after the following code fragment runs? Int i = 60; Int j = 50; Int count = 0; While (count < 5) { I = i + i; I = i + 1; J = j - 1; J = j - j; Count++; } System.out.println("i=" + i + ", j=" + j);
Multiple Choice
Answer:
Tags
Choose question tag
close menu
arrow
How many times does the code snippet given below display "Loop Execution"? Int i = 1; While (i != 10) { System.out.println ("Loop Execution"); I++; }
Multiple Choice
Answer:
Tags
Choose question tag
close menu
arrow
What is the output of the code snippet given below? String s = "abcde"; Int i = 1; While (i < 5) { System.out.print); I++; }
Multiple Choice
Answer:
Tags
Choose question tag
close menu
arrow
What is the output of the code snippet given below? Int i = 0; While (i != 9) { System.out.println("" + i); I = i + 2; }
Multiple Choice
Answer:
Tags
Choose question tag
close menu
arrow
What is the output of the code snippet given below? String s = "12345"; Int i = 1; While (i < 5) { System.out.print); I++; }
Multiple Choice
Answer:
Tags
Choose question tag
close menu
arrow
What are the values of i and j after the following code snippet is run? Int i = 10; Int j = 20; Int count = 0; While (count < 5) { I = i + i; I = i + 1; J = j - 1; J = j - j; Count++; } System.out.println("i = " + i + ", j = " + j);
Multiple Choice
Answer:
Tags
Choose question tag
close menu
arrow
Which error type does the "off-by-one" error belong to?
Multiple Choice
Answer:
Tags
Choose question tag
close menu
arrow
What is the output of the code fragment given below? Int i = 0; Int j = 0; While (i < 125) { I = i + 2; J++; } System.out.println(j);
Multiple Choice
Answer:
Tags
Choose question tag
close menu
arrow
What is the output of the following code fragment? Int i = 1; Int sum = 0; While (i <= 11) { Sum = sum + i; I++; } System.out.println("The value of sum is " + sum);
Multiple Choice
Answer:
Tags
Choose question tag
close menu
arrow
What is the output of the following code snippet? Int i = 1; While (i < 10) { System.out.print(i + " "); I = i + 2; If (i == 5) { I = 9; } }
Multiple Choice
Answer:
Tags
Choose question tag
close menu
arrow
How many times will the following loop run? Int i = 0; While (i < 10) { System.out.println(i); I++; }
Multiple Choice
Answer:
Tags
Choose question tag
close menu
arrow
What is the output of the following code snippet? double a = 2; Int n = 16; Double r = 1; Double b = a; Int i = n; While (i > 0) { If (i % 2 == 0) // n is even { B = b * b; I = i / 2; } Else { R = r * b; I--; } } System.out.println("r = " + r);
Multiple Choice
Answer:
Tags
Choose question tag
close menu
arrow
What is the output of the code fragment given below? Int i = 0; Int j = 0; While (i < 27) { I = i + 2; J++; } System.out.println("j=" + j);
Multiple Choice
Answer:
Tags
Choose question tag
close menu
Showing 1 - 20 of 128