NEW
Font size
WorksheetsJava Quiz for Kids
Total questions: 49
Worksheet time: 25mins
What will this code print? System.out.print("Hello"); System.out.println(" World");
Hello World
Hello
HelloWorld
Hello World (on separate lines)
What is the output of this code? int x = 5; for(int i = 0; i < x; i++) { System.out.print(i + " "); }
0 1 2 3 4
1 2 3 4 5
0 1 2 3 4 5
5 4 3 2 1
Which is used to read input from the user?
PrintWriter
Scanner
System.in.println
StringReader
Choose the correct way to declare a float value.
float a = 5.2;
float a = "5.2f";
float a = 5.2f;
float a = "5.2";
What is the result of this code? int num = 3; if(num > 5) { System.out.println("Big"); } else { System.out.println("Small"); }
Big
Small
Error
Nothing
How many times will this loop run? for(int i = 1; i <= 3; i++) { System.out.println("Hi"); }
1
3
2
0
Which of the following is used to print without a new line?
System.println
print()
System.out.print()
echo()
What will this code print? double d = 7.5; System.out.println(d);
7
7.0
7.5
Error
What will be printed? String name = "Alex"; System.out.println(name);
name
Alex
"Alex"
Error
What does Scanner sc = new Scanner(System.in); do?
Writes to screen
Creates a Scanner object
Prints text
Closes the program
What is the correct way to read an integer input?
sc.readInt();
sc.int();
sc.nextInt();
sc.input();
Choose the correct if-else syntax.
if { } else { }
if () { } else () { }
if(condition) { } else { }
if: then else:
Which of these is a valid double declaration?
double x = 5.5;
double x = "5.5";
double x = 5f;
double x = '5';
What is the output? System.out.print("3 + 4 = "); System.out.println(3 + 4);
3 + 4 = 7
7
3 + 4 = 3 + 4
Error
How do you print multiple lines?
Use System.out.print twice
Use System.out.println twice
Use println() inside loop
All of the above
What will this code print? float x = 4.5f; System.out.println(x);
4.5
4.5f
"4.5"
Error
Which loop repeats something many times?
if
for
else
What does this print? int n = 2; if(n == 2) { System.out.println("Two"); } else { System.out.println("Not Two"); }
Two
Not Two
2
Error
Which is correct?
System.print();
System.out.println();
println.System.out();
out.System.print();
How many times will this run? for(int i = 0; i < 4; i++) { System.out.println("Looping"); }
3
4
5
0
What is the output? System.out.print("Hi "); System.out.print("there!");
Hi there!
Hi there!
there! Hi
Error
Which line takes a String input from user?
sc.getString();
sc.next();
sc.input();
sc.readString();
What is the type of this variable? String text = "Fun";
int
float
String
double
What will be printed? for(int i = 1; i <= 2; i++) { System.out.println("Go"); }
Go
Go Go
1 2
Nothing
What is the result? int age = 10; if(age < 5) { System.out.println("Tiny"); } else if(age < 13) { System.out.println("Kid"); } else { System.out.println("Teen"); }
Tiny
Kid
Teen
Nothing
Which will show decimal numbers?
int
float
String
boolean
What is printed? System.out.println("4" + 3);
7
43
4 3
Error
What does this do? for(int i = 0; i < 2; i++) { System.out.println(i); }
Prints 0 1
Prints 1 2
Infinite loop
Nothing
Which input reads a decimal value?
sc.nextDouble();
sc.nextInt();
sc.get();
sc.input();
What type is this? double pi = 3.14;
int
float
double
String
What does this output? System.out.print("Good "); System.out.println("Morning");
GoodMorning
Good Morning
Good Morning
Error
What is printed? String fruit = "Apple"; System.out.println(fruit);
fruit
Apple
"Apple"
Error
Which of these is a float?
3
3.14
3.14f
"3.14"
What is the output of this loop? for(int i = 1; i <= 2; i++) { System.out.print(i + " "); }
0 1
1 2
1 2 3
2 1
What will this print? float a = 2.5f; System.out.println(a + 1);
3.5
2.5 1
2.51
Error
What is the value of x? int x = 10 + 5;
15
105
10 + 5
Error
What does this print? System.out.print("Best"); System.out.print(" Day");
Best Day
Best Day
BestDay
Day Best
How do you create a Scanner?
new Scanner;
Scanner = new();
Scanner sc = new Scanner(System.in);
Scanner.sc(System.in);
What happens here? int a = 5; if(a > 2) { System.out.println("Yes"); }
No
Yes
Error
Nothing
What does this loop print? for(int i = 0; i < 3; i++) { System.out.print("*"); }
*
***
3
Nothing
Choose correct if-else structure
if() { } else { }
if[] { } else { }
if then else
if() else()
What is printed? System.out.print("9"); System.out.println("9");
18
99
9 9
Error
What is correct input for float?
sc.nextFloat();
sc.float();
sc.read();
sc.inputFloat();
How many times will this loop run? for(int i = 0; i < 1; i++) { System.out.println("One"); }
1
0
Infinite
Error
Which is correct?
int x = "3";
String s = 3;
float f = 3.0f;
double d = "3.0";
Which will show "3.0"?
float x = 3;
double x = 3;
float x = 3.0f;
int x = 3.0;
What will this print? System.out.print("X"); System.out.print("Y");
XY
X Y
YX
X Y
What does this do? int i; for(i = 0; i < 2; i++) { System.out.println("Go!"); }
Go!
Go! Go!
Nothing
Error
What is the type of 5?
float
double
String
int
