NEW
Font size
WorksheetsScanner & If Statements
Total questions: 18
Worksheet time: 18mins
14 >= 14
15 > 15
16 != 16
18 >= 19
2 + 2 == 4
Math.pow(2, 3) >= 9;
True/False: The body of an "if" statement will only be executed if the condition is true.
True
False
What happens to the code in the body of an "if" statement if the condition is false?
The computer determines if it is essential to the program and if it is, then the code is executed anyway.
The code moves to a coastal city, attempting to find love and start a family. However, low waged and crushing mortgage rates lead to it moving back home where it sits, hoping that one day it will be executed.
The code is skipped.
The code stages a revolution and attempts to take over the program, ultimately unsuccessfully, which leads to it not being executed.
Which of these can be paired with an "if" statement to represent other outcomes of a scenario?
or
else
but
sheboygan
Which symbol means "not equal to"?
==
<=
>=
!=
Which of the following is the correct way to instantiate a Scanner that receives input from the user?
Scanner in = new Scanner(System.in);
Scanner in = System.in();
scanner in = Scanner(System.in);
import java.util.Scanner;
Which of the following scanner methods reads the next whole number?
nextLine()
next()
nextInt()
nextNumber()
If both a and b are true, what is the outcome of the following statement?
(!a&&b) || a
true
false
What is the value of num after this statement is executed?
int num = 23;
if(num>20) { num = 20; }
else { num = 30; }
20
30
23
true
Which of the following should replace the <1> to correctly receive any string received from the user?
Scanner s = new Scanner(System.in);
String sent = <1>;
System.out.println(sent);
nextLine();
s.nextInt();
s.nextDouble();
s.nextLine();
Which of the following scanner methods receives the next decimal?
Scanner.nextInt();
Scanner.nextDouble();
Scanner.next();
Scanner.nextLine();
which of the following has the boolean value of true?
3 = 3
!(3 == 3)
"foo".isEqualTo("foo")
true || false
which is the correct way to write an if statement?
if foo: bar
if(foo)
{ bar }
if(foo): bar
if foo then bar
If the user inputs:
Karl is 17 he has a 93.45 in spanish
and the code reads:
Scanner s = new Scanner(System.in);
String answer = s.next();
what is the value of answer?
17.0
"is 17 he has a 93.45 in spanish"
"Karl"
93.45
what does this peice of code evaluate to?
boolean raining = true;
String answer;
if(!(raining)) {answer = "Yay!"}
Else {answer = "Boo!"}
Yay!
Boo!
true
false
What would be the value of num?
int num = 0;
if(num>3) { num = 2; }
if(num<3) {num = 3; }
if (num == 0) { num = 12; }
2
3
12
error
