# Big Java Binder Early Objects

Computing

## Quiz 6 : Loops Study Flashcards  Looking for Programming Homework Help?

## Quiz 6 :Loops

Question Type  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

B

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

C

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

C

Tags
Choose question tag  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
Tags
Choose question tag  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
Tags
Choose question tag  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
Tags
Choose question tag  How many times does the following code fragment display "Hi"? Int i = 10; While (i >= 0) { System.out.println("Hi"); I--; }
Multiple Choice
Tags
Choose question tag  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
Tags
Choose question tag  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
Tags
Choose question tag  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
Tags
Choose question tag  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
Tags
Choose question tag  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
Tags
Choose question tag  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
Tags
Choose question tag  Which error type does the "off-by-one" error belong to?
Multiple Choice
Tags
Choose question tag  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
Tags
Choose question tag  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
Tags
Choose question tag  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
Tags
Choose question tag  How many times will the following loop run? Int i = 0; While (i < 10) { System.out.println(i); I++; }
Multiple Choice
Tags
Choose question tag  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   