2/12/2018
What is the value of the declared boolean after execution of the following code?
Peer Instruction 2
Conditionals (Selection)
boolean canDrive; int age = 16; if (age > 16) canDrive = true; System.out.println(canDrive);
A. false B. true C. Will not compile!
cs163/164: Peer 2 - Conditionals - Fall Semester 2016
What is the value of the declared boolean after execution of the following code? boolean canDrive; int age = 16; if (age > 16) canDrive = true; System.out.println(canDrive);
A. false B. true C. Will not compile!
cs163/164: Peer 2 - Conditionals - Fall Semester 2016
Question - 2
Question - 1
What is the value of the declared boolean after execution of the following code? int i = 100, j = 200, k = 300; boolean myBoolean; if (i = 0); radius = 1; B. if (radius < 0) else radius = 2; C. if (radius < 0); else; radius = 3; D. boolean b = (2 < 1);
E.
cs163/164: Peer 2 - Conditionals - Fall Semester 2016
switch (c) { case ‘a’: case ‘b’: case ‘c’: c = ‘z’; break; }
Question - 8
What is the value of myInteger after execution of the following code? int myInteger = -1; if (myInteger++ < 0) { myInteger = myInteger + 2; } else { myInteger = myInteger + 1; }
A. B. C. D. E.
cs163/164: Peer 2 - Conditionals - Fall Semester 2016
0 1 2 3 None of the above
Question - 10
What is the value of myInteger after execution of the following code? int myInteger = -1; if (myInteger++ < 0) { myInteger = myInteger + 2; } else { myInteger = myInteger + 1; }
A. B. C. D. E.
cs163/164: Peer 2 - Conditionals - Fall Semester 2016
0 1 2 3 None of the above
Question - 9
What is the value of myInteger after execution of the following code? int myInteger = 1; if (-- myInteger == 1) { myInteger += 4; } else { myInteger += 5; }
A. B. C. D. E.
cs163/164: Peer 2 - Conditionals - Fall Semester 2016
3 4 5 6 None of the above
Question - 11
3
2/12/2018
What is the value of myInteger after execution of the following code? int myInteger = 1; if (-- myInteger == 1) { myInteger += 4; } else { myInteger += 5; }
A. B. C. D. E.
3 4 5 6 None of the above
cs163/164: Peer 2 - Conditionals - Fall Semester 2016
Question - 12
What is the value of myChar after execution of the following code? char myChar = ’@’; switch (myChar ) { case ‘#’: myChar = ‘a’; case ’@’: myChar = ‘b’; case ‘a’: myChar = ‘c’; break; default: myChar = ’d’; }
A. B. C. D.
cs163/164: Peer 2 - Conditionals - Fall Semester 2016
’a’ ‘b’ ‘c’ ‘d’
Question - 13
What is the value of myChar after execution of the following code? char myChar = ’@’; switch (myChar ) { case ‘#’: myChar = ‘a’; case ’@’: myChar = ‘b’; case ‘a’: myChar = ‘c’; break; default: myChar = ’d’; }
A. B. C. D.
cs163/164: Peer 2 - Conditionals - Fall Semester 2016
’a’ ‘b’ ‘c’ ‘d’
Math, Characters, Strings Question - 14
4
2/12/2018
Which line correctly creates the myString object with the text "Hello World"?
Which line correctly creates the myString object with the text "Hello World"?
Select the one correct answer.
Select the one correct answer.
A. B. C. D. E.
A. B. C. D. E.
String myString = (Hello World); String myString = ‘Hello World’; String myString = "Hello” + “ World"; String myString = new String(Hello World); None of the above
cs163/164: Peer 3 - Math/Characters/Strings - Fall Semester 2016
Question - 16
What will the code shown below print to the console?
String myString = (Hello World); String myString = ‘Hello World’; String myString = "Hello” + “ World"; String myString = new String(Hello World); None of the above
cs163/164: Peer 3 - Math/Characters/Strings - Fall Semester 2016
What will the code shown below print to the console?
String s = "Computer science is okay!"; System.out.println(s.substring(16));
String s = "Computer science is okay!"; System.out.println(s.substring(16));
A. B. C. D. E.
A. B. C. D. E.
"Computer science" " is okay!" "is okay!" "Computer scienceis okay!" None of the above cs163/164: Peer 3 - Math/Characters/Strings - Fall Semester 2016
Question - 18
Question - 17
"Computer science" " is okay!" "is okay!" "Computer scienceis okay!" None of the above cs163/164: Peer 3 - Math/Characters/Strings - Fall Semester 2016
Question - 19
5
2/12/2018
What is objectionable with respect to the code shown below?
What is objectionable with respect to the code shown below?
1 Math math = new Math(); 2 System.out.println(Math.sin(Math.toRadians(90))); 3 System.out.println(Math.min(1.0, 2.0));
1 Math math = new Math(); 2 System.out.println(Math.sin(Math.toRadians(90))); 3 System.out.println(Math.min(1.0, 2.0));
A. B. C. D. E.
A. B. C. D. E.
Instantiation of Math object not allowed. (Line 1) Object instead of class to call method? (Line 2) Too many parameter to method! (Line 3) All of the above Nothing is wrong cs163/164: Peer 3 - Math/Characters/Strings - Fall Semester 2016
Question - 20
What will the code shown below print to the console?
Instantiation of Math object not allowed. (Line 1) Object instead of class to call method? (Line 2) Too many parameter to method! (Line 3) All of the above Nothing is wrong cs163/164: Peer 3 - Math/Characters/Strings - Fall Semester 2016
Question - 21
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));
System.out.println(Character.isDigit(‘A’) + "," + Character.isLetter(’z’) + "," + Character.isLowerCase(’&’) + "," + Character.isLetter("5A%".charAt(1));
A. B. C. D.
A. B. C. D.
true,false,true,false false,true,false,true false,true,false,false false,true,true,true cs163/164: Peer 3 - Math/Characters/Strings - Fall Semester 2016
Question - 22
true,false,true,false false,true,false,true false,true,false,false false,true,true,true cs163/164: Peer 3 - Math/Characters/Strings - Fall Semester 2016
Question - 23
6
2/12/2018
What are the values of the double and integer after the code shown below executes?
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);
String myString = "1.234"; double myDouble = Double.parseDouble(myString); int myInteger = Integer.parseInt(myString);
A. B. C. D.
A. B. C. D.
1.234, 0 1.234, 1 1.234, 2 Program gets an exception! cs163/164: Peer 3 - Math/Characters/Strings - Fall Semester 2016
Question - 24
1.234, 0 1.234, 1 1.234, 2 Program gets an exception! cs163/164: Peer 3 - Math/Characters/Strings - Fall Semester 2016
Question - 25
What value is printed for the loop variable when the code shown below runs?
Peer Instruction 4
Control Loops
int loop = 0; while (loop