WorksheetsJava conditional/loop/method/user input
Total questions: 23
Worksheet time: 21mins
(int) (Math.random()*100) generates a random number between 0 and 100, including 0 and 100
True
False
Which of the following represents a single line comment in Java?
/* Comment */
<!-- Comment -->
// Comment
# Comment
Which of the following represents a multi-line comment in Java?
<!-- Comment >
// Comment
/* Comment */
# Comment
public static _____ statement(int x, int y){
String z = "x is: " + x + "and y is: " + y;
return z }
What should the return type be?
void
int
double
String
public static ________ average(int x, int y){
return (double) x / y;
}
What should the return type be?
void
int
double
String
This is an example of a non-return method.
True
False
The name of this method is ....
Oddsum
int Oddsum
int Oddsum (int number)
return totaloddsum
Method make codes more readable and easier to debug.
True
False
What is the correct data type for the following variable:
__________ myAnswer = false;
String
char
int
boolean
what is the meaning of the code below:
x++;
x = 1;
x = x + 1;
x = 2
What is the output of the code shown in the image?
False
Next Round
Game Finished
finished
Which statement(s) properly implements an equality comparison of two String objects?
A, only
B, only
A and C
All are acceptable
What is the output of the code shown?
Sandy
Squidward
Patrick
Spongebob
What is the output of the code shown?
Hello!!
Goodbye!!
A while loop has the following format:
while (condition)
{
...
}
while
{
...
}
continue while (condition)
{
...
}
while [condition]
[
...;
]
How many stars are printed?
7
3
4
5
Infinite Loop
What does the following code print?
5 6 7 8 9
4 5 6 7 8 9 10 11 12
3 5 7 9 11
3 4 5 6 7 8 9 10 11 12
If a loop condition is never satisfied then the loop does not execute.
2
5
7
9
13
20
int x = 0;
while (x < 4) {
x = x + 1;
}
System.out.println("x is " + x);
Which Scanner class method is used to read integer value from the user?
next()
nextInteger()
nextInt()
readInt()
Which is the correct syntax to declare Scanner class object?
Scanner objectName= Scanner();
Scanner objectName= new Scanner();
Scanner objectName= Scanner(System.in);
Scanner objectName= new Scanner(System.in);
