Week6Assignment

Week6Assignment - x++; } } } } A)0 B) 1 C) 5 D) 2 E) 3 Q4:...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Assignment 5 Repetition Statements
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Q1: What is the result of executing the following program? public class WhileExample { public static void main(String[] args) { int x = 0; while(x > -1) System.out.println("x= " + x); } } A) Nothing gets printed B) x= -1 gets printed once C) x= 0 gets printed indefinitely D) Compile error E) Prints x= -1 then x= 0
Background image of page 2
Q2: Which of these is true regarding do-while statements? A) do-while statements cannot be nested within one another. B) do-while statements cannot lead to infinite loops C) do-while statements cannot contain method invocations in the body of the loop. D) The minimum number of times the loop is executed in a do-while loop is zero E) do-while loops do not permit the use of comma
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Q3: How many times does “A” get printed in the following program public class WhileExample { public static void main(String[] args) { int x = 0; while (x < 5) { while (x < 5) { System.out.print("A");
Background image of page 4
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: x++; } } } } A)0 B) 1 C) 5 D) 2 E) 3 Q4: What is the output of the following program? public class WhileExample { public static void main(String args) { boolean done=false; for(; !done ;) { System.out.println(&quot;Not done&quot;); done=true; } } } A) Error: initialization is missing in the for loop B) Error: iteration is missing in the for loop C) Error: condition does not evaluate to boolean D) Prints Not done once. E) Nothing gets printed and no error. Q5: Choose the correct statement among the following A) Only integers are valid counter variable types in for loops. B) There are no restrictions on the number of statements inside a loop. C) The break statement only works inside the innermost loop of nested loops. D) Any changes to variables made inside loops are not visible outside the loop. E) Minimum number of times the loop is executed in a for loop is one....
View Full Document

Page1 / 6

Week6Assignment - x++; } } } } A)0 B) 1 C) 5 D) 2 E) 3 Q4:...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online