loop++; System.out.println(loop);

Save this PDF as:
 WORD  PNG  TXT  JPG

Size: px
Start display at page:

Download "loop++; System.out.println(loop);"

Transcription

1 What value is printed for the loop variable when the code shown below runs? int loop = 0; while (loop <= 10) { loop++; System.out.println(loop); A. 0 to 9 B. 0 to 10 C. 1 to 10 D. 1 to 11 E. Will not compile! cs163/164: Peer 4 - Control Loops - Fall Semester 2016 Question - 1

2 What value is printed for the loop variable when the code shown below runs? int loop = 0; while (loop <= 10) { loop++; System.out.println(loop); A. 0 to 9 B. 0 to 10 C. 1 to 10 D. 1 to 11 E. Will not compile! cs163/164: Peer 4 - Control Loops - Fall Semester 2016 Question - 2

3 What value is printed for the loop variable when the code shown below runs? int loop =0; while (loop <= 10) { loop++; System.out.println(loop); A. 9 B. 10 C. 11 D. 12 E. Will not compile! cs163/164: Peer 4 - Control Loops - Fall Semester 2016 Question - 3

4 What value is printed for the loop variable when the code shown below runs? int loop =0; while (loop <= 10) { loop++; System.out.println(loop); A. 9 B. 10 C. 11 D. 12 E. Will not compile! cs163/164: Peer 4 - Control Loops - Fall Semester 2016 Question - 4

5 How many times will the body of the do while loop execute? byte loop = -1; do { loop++; while (loop < 0); A. 0 times B. 1 time C. 2 times D. 128 times E. Infinite loop! cs163/164: Peer 4 - Control Loops - Fall Semester 2016 Question - 5

6 How many times will the body of the do while loop execute? byte loop = -1; do { loop++; while (loop < 0); A. 0 times B. 1 time C. 2 times D. 128 times E. Infinite loop! cs163/164: Peer 4 - Control Loops - Fall Semester 2016 Question - 6

7 cs163/164: Peer 4 - Control Loops - Fall Semester 2016 How many times will the body of the do while loop execute? byte loop = 0; do { loop++; while (loop > 0); A. 0 times B. 1 time C. 2 times D. 128 times E. Infinite loop! Questi on - 7

8 cs163/164: Peer 4 - Control Loops - Fall Semester 2016 How many times will the body of the do while loop execute? byte loop = 0; do { loop++; while (loop > 0); A. 0 times B. 1 time C. 2 times D. 128 times E. Infinite loop! Questi on - 8

9 cs163/164: Peer 3 - Math/Characters/Strings - Fall Semester 2016 What will the code shown below print to the console? System.out.println( Character.isDigit( A ) + "," + Character.isLetter( z ) + "," + Character.isLowerCase( & ) + "," + Character.isLetter("5A%".charAt(1)); A. true,false,true,false B. false,true,false,true C. false,true,false,false D. false,true,true,true Questi on - 9

10 cs163/164: Peer 3 - Math/Characters/Strings - Fall Semester 2016 What will the code shown below print to the console? System.out.println( Character.isDigit( A ) + "," + Character.isLetter( z ) + "," + Character.isLowerCase( & ) + "," + Character.isLetter("5A%".charAt(1)); A. true,false,true,false B. false,true,false,true C. false,true,false,false D. false,true,true,true Questio n - 10

11 cs163/164: Peer 3 - Math/Characters/Strings - Fall Semester 2016 What are the values of the double and integer after the code shown below executes? String mystring = "1.234"; double mydouble = Double.parseDouble(myString); int myinteger = Integer.parseInt(myString); A , 0 B , 1 C , 2 D. Program gets an exception! Questio n - 11

12 cs163/164: Peer 3 - Math/Characters/Strings - Fall Semester 2016 What are the values of the double and integer after the code shown below executes? String mystring = "1.234"; double mydouble = Double.parseDouble(myString); int myinteger = Integer.parseInt(myString); A , 0 B , 1 C , 2 D. Program gets an exception! Questio n - 12

13 cs163/164: Peer 4 - Control Loops - Fall Semester 2016 How many lines does the nested loop shown below print? for (int row = 0; row < 10; row += 2) { for (int col = 0; col < 50; col += 10) { System.out.println(row + "," + col) ; A. 20 times B. 25 times C. 36 times D. 500 times E. Different each time it runs! Questio n - 13

14 cs163/164: Peer 4 - Control Loops - Fall Semester 2016 How many lines does the nested loop shown below print? for (int row = 0; row < 10; row += 2) { for (int col = 0; col < 50; col += 10) { System.out.println(row + "," + col) ; A. 20 times B. 25 times C. 36 times D. 500 times E. Different each time it runs! Questio n - 14

15 cs163/164: Peer 4 - Control Loops - Fall Semester 2016 Which of the following correctly prints the entire contents of the string? String s = "Programming is fun!"; A. for (int i=1; i< s.length(); i++) System.out.print(s.charAt(i)); B. for (int i=1; i<= s.length(); ++i) System.out.print(s.charAt(i)); C. for (int i=0; i<= s.length(); i++) System.out.print(s.charAt(i)); D. for (int i=0; i< s.length(); ++i) System.out.print(s.charAt(i)); Questio n - 15

16 cs163/164: Peer 4 - Control Loops - Fall Semester 2016 Which of the following correctly prints the entire contents of the string? String s = "Programming is fun!"; A. for (int i=1; i< s.length(); i++) System.out.print(s.charAt(i)); B. for (int i=1; i<= s.length(); ++i) System.out.print(s.charAt(i)); C. for (int i=0; i<= s.length(); i++) System.out.print(s.charAt(i)); D. for (int i=0; i< s.length(); ++i) System.out.print(s.charAt(i)); Questio n - 16

17 cs163/164: Peer 4 - Control Loops - Fall Semester 2016 What is the last thing printed by the for loop shown below? for (String s = "Hello"; s.length() <= 10; s += "!") { System.out.println(s); A. Hello B. Hello! C. Hello!!!!! D.!!!!! E. None of the above Questio n - 17

18 cs163/164: Peer 4 - Control Loops - Fall Semester 2016 What is the last thing printed by the for loop shown below? for (String s = "Hello"; s.length() <= 10; s += "!") { System.out.println(s); A. Hello B. Hello! C. Hello!!!!! D.!!!!! E. None of the above Questio n - 18