Services
Discover
Homeschooling
Ask a Question
Log in
Sign up
Filters
Done
Question type:
Essay
Multiple Choice
Short Answer
True False
Matching
Topic
Computing
Study Set
Big Java Binder Early Objects
Quiz 6: Loops
Path 4
Access For Free
Share
All types
Filters
Study Flashcards
Practice Exam
Learn
Question 1
Multiple Choice
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. ") ; } }
Question 2
Multiple Choice
What output does this while loop generate? j = 6; While (j > 0) { System.out.print(j + ", ") ; J--; }
Question 3
Multiple Choice
How many times does the code snippet below display "Hello"? Int i = 0; While (i != 15) { System.out.println("Hello") ; I++; }
Question 4
Multiple Choice
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) ;
Question 5
Multiple Choice
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; }
Question 6
Multiple Choice
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; } }
Question 7
Multiple Choice
How many times does the following code fragment display "Hi"? Int i = 10; While (i >= 0) { System.out.println("Hi") ; I--; }
Question 8
Multiple Choice
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) ;
Question 9
Multiple Choice
How many times does the code snippet given below display "Loop Execution"? Int i = 1; While (i != 10) { System.out.println ("Loop Execution") ; I++; }
Question 10
Multiple Choice
What is the output of the code snippet given below? String s = "abcde"; Int i = 1; While (i < 5) { System.out.print) ; I++; }
Question 11
Multiple Choice
What is the output of the code snippet given below? Int i = 0; While (i != 9) { System.out.println("" + i) ; I = i + 2; }
Question 12
Multiple Choice
What is the output of the code snippet given below? String s = "12345"; Int i = 1; While (i < 5) { System.out.print) ; I++; }
Question 13
Multiple Choice
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) ;