wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Java Quiz for Kids

Total questions: 49

Worksheet time: 25mins

Name
Class
Date
1.

What will this code print? System.out.print("Hello"); System.out.println(" World");

a)

Hello World

b)

Hello

c)

HelloWorld

d)

Hello World (on separate lines)

2.

What is the output of this code? int x = 5; for(int i = 0; i < x; i++) { System.out.print(i + " "); }

a)

0 1 2 3 4

b)

1 2 3 4 5

c)

0 1 2 3 4 5

d)

5 4 3 2 1

3.

Which is used to read input from the user?

a)

PrintWriter

b)

Scanner

c)

System.in.println

d)

StringReader

4.

Choose the correct way to declare a float value.

a)

float a = 5.2;

b)

float a = "5.2f";

c)

float a = 5.2f;

d)

float a = "5.2";

5.

What is the result of this code? int num = 3; if(num > 5) { System.out.println("Big"); } else { System.out.println("Small"); }

a)

Big

b)

Small

c)

Error

d)

Nothing

6.

How many times will this loop run? for(int i = 1; i <= 3; i++) { System.out.println("Hi"); }

a)

1

b)

3

c)

2

d)

0

7.

Which of the following is used to print without a new line?

a)

System.println

b)

print()

c)

System.out.print()

d)

echo()

8.

What will this code print? double d = 7.5; System.out.println(d);

a)

7

b)

7.0

c)

7.5

d)

Error

9.

What will be printed? String name = "Alex"; System.out.println(name);

a)

name

b)

Alex

c)

"Alex"

d)

Error

10.

What does Scanner sc = new Scanner(System.in); do?

a)

Writes to screen

b)

Creates a Scanner object

c)

Prints text

d)

Closes the program

11.

What is the correct way to read an integer input?

a)

sc.readInt();

b)

sc.int();

c)

sc.nextInt();

d)

sc.input();

12.

Choose the correct if-else syntax.

a)

if { } else { }

b)

if () { } else () { }

c)

if(condition) { } else { }

d)

if: then else:

13.

Which of these is a valid double declaration?

a)

double x = 5.5;

b)

double x = "5.5";

c)

double x = 5f;

d)

double x = '5';

14.

What is the output? System.out.print("3 + 4 = "); System.out.println(3 + 4);

a)

3 + 4 = 7

b)

7

c)

3 + 4 = 3 + 4

d)

Error

15.

How do you print multiple lines?

a)

Use System.out.print twice

b)

Use System.out.println twice

c)

Use println() inside loop

d)

All of the above

16.

What will this code print? float x = 4.5f; System.out.println(x);

a)

4.5

b)

4.5f

c)

"4.5"

d)

Error

17.

Which loop repeats something many times?

a)

if

b)

for

c)

else

d)

print

18.

What does this print? int n = 2; if(n == 2) { System.out.println("Two"); } else { System.out.println("Not Two"); }

a)

Two

b)

Not Two

c)

2

d)

Error

19.

Which is correct?

a)

System.print();

b)

System.out.println();

c)

println.System.out();

d)

out.System.print();

20.

How many times will this run? for(int i = 0; i < 4; i++) { System.out.println("Looping"); }

a)

3

b)

4

c)

5

d)

0

21.

What is the output? System.out.print("Hi "); System.out.print("there!");

a)

Hi there!

b)

Hi there!

c)

there! Hi

d)

Error

22.

Which line takes a String input from user?

a)

sc.getString();

b)

sc.next();

c)

sc.input();

d)

sc.readString();

23.

What is the type of this variable? String text = "Fun";

a)

int

b)

float

c)

String

d)

double

24.

What will be printed? for(int i = 1; i <= 2; i++) { System.out.println("Go"); }

a)

Go

b)

Go Go

c)

1 2

d)

Nothing

25.

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"); }

a)

Tiny

b)

Kid

c)

Teen

d)

Nothing

26.

Which will show decimal numbers?

a)

int

b)

float

c)

String

d)

boolean

27.

What is printed? System.out.println("4" + 3);

a)

7

b)

43

c)

4 3

d)

Error

28.

What does this do? for(int i = 0; i < 2; i++) { System.out.println(i); }

a)

Prints 0 1

b)

Prints 1 2

c)

Infinite loop

d)

Nothing

29.

Which input reads a decimal value?

a)

sc.nextDouble();

b)

sc.nextInt();

c)

sc.get();

d)

sc.input();

30.

What type is this? double pi = 3.14;

a)

int

b)

float

c)

double

d)

String

31.

What does this output? System.out.print("Good "); System.out.println("Morning");

a)

GoodMorning

b)

Good Morning

c)

Good Morning

d)

Error

32.

What is printed? String fruit = "Apple"; System.out.println(fruit);

a)

fruit

b)

Apple

c)

"Apple"

d)

Error

33.

Which of these is a float?

a)

3

b)

3.14

c)

3.14f

d)

"3.14"

34.

What is the output of this loop? for(int i = 1; i <= 2; i++) { System.out.print(i + " "); }

a)

0 1

b)

1 2

c)

1 2 3

d)

2 1

35.

What will this print? float a = 2.5f; System.out.println(a + 1);

a)

3.5

b)

2.5 1

c)

2.51

d)

Error

36.

What is the value of x? int x = 10 + 5;

a)

15

b)

105

c)

10 + 5

d)

Error

37.

What does this print? System.out.print("Best"); System.out.print(" Day");

a)

Best Day

b)

Best Day

c)

BestDay

d)

Day Best

38.

How do you create a Scanner?

a)

new Scanner;

b)

Scanner = new();

c)

Scanner sc = new Scanner(System.in);

d)

Scanner.sc(System.in);

39.

What happens here? int a = 5; if(a > 2) { System.out.println("Yes"); }

a)

No

b)

Yes

c)

Error

d)

Nothing

40.

What does this loop print? for(int i = 0; i < 3; i++) { System.out.print("*"); }

a)

*

b)

***

c)

3

d)

Nothing

41.

Choose correct if-else structure

a)

if() { } else { }

b)

if[] { } else { }

c)

if then else

d)

if() else()

42.

What is printed? System.out.print("9"); System.out.println("9");

a)

18

b)

99

c)

9 9

d)

Error

43.

What is correct input for float?

a)

sc.nextFloat();

b)

sc.float();

c)

sc.read();

d)

sc.inputFloat();

44.

How many times will this loop run? for(int i = 0; i < 1; i++) { System.out.println("One"); }

a)

1

b)

0

c)

Infinite

d)

Error

45.

Which is correct?

a)

int x = "3";

b)

String s = 3;

c)

float f = 3.0f;

d)

double d = "3.0";

46.

Which will show "3.0"?

a)

float x = 3;

b)

double x = 3;

c)

float x = 3.0f;

d)

int x = 3.0;

47.

What will this print? System.out.print("X"); System.out.print("Y");

a)

XY

b)

X Y

c)

YX

d)

X Y

48.

What does this do? int i; for(i = 0; i < 2; i++) { System.out.println("Go!"); }

a)

Go!

b)

Go! Go!

c)

Nothing

d)

Error

49.

What is the type of 5?

a)

float

b)

double

c)

String

d)

int