time() && $theUser1!="1234") die(); ?> AP CS
Loading
notes intro/old submit AP Problems the dump links
 

Quiz 10a - loops

 

 

 

id:

1.Which of the following would not compile as the condition of a while loop

while (x!=5) while(true) while (name=="Cam") while (name.equals("Wild")) all of them work

2. True or false: You need to have braces - { } - around the body of a for loop statements

 

true false

 

3. What will be printed after the following code?

x=5;
while (x>=5)
{
     System.out.print(x);
     x=x-2;
}

 

 

4. What is the value of x after the following code:

x=5;
while (x>=3)
     x=x/0;

infinite loop, never ends compile time error runtime error x=5 x=0

 

5. What is the value of x after the following code:

x=50;
for (int i=5;i>=3; i--)
     x-=i;

 

6. What will be printed after the following code:

for (int i=0;i<=3; i++)
{
    for (int x=i; x < i+2; x++)
		System.out.print(x);
    System.out.print("_");
}