wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java Operator and Control Flow Statement Test

Total questions: 84

Worksheet time: 2hrs 6mins

Name
Class
Date
1.

++ increases the value of a variable by 1

a)

assignment operator

b)

decrement operator

c)

increment operator

d)

sentinel

2.

What's the value of below?


int i=5;

System.out.println(i++);

System.out.println(i);

System.out.println(++i);

a)

5

6

7

b)

6

6

7

c)

6

7

8

d)

5

5

6

3.

Which statement(s) are equivalent to i = i + 1?

a)

i += 1

b)

i++

c)

i -= 1

d)

i--

4.

What will be the output of the program?

class Test

{

public static void main(String [] args)

{

int x=20;

String sup = (x < 15) ? "small" : (x < 22)? "tiny" : "huge";

System.out.println(sup);

}

}

a)

small

b)

tiny

c)

huge

d)

Compilation fails

5.

Please write correct output in following space-

a)

10

b)

20

c)

No Output

d)

Error

6.

--------- is a symbol, that operates on operands and produce a result

a)

operands

b)

variables

c)

operators

d)

Ternary

7.

Choose the logical operators

a)

And

b)

Less than

c)

OR

d)

Not Equal

8.

The result of AND operator is always true, if both the conditions results are _____

a)

True

b)

False

9.

What is the value in variable A?

A+=112

a)

112

b)

111

c)

113

d)

130

10.

in Java every statement is end with _____?

a)

Comma

b)

Colon

c)

Semicolon

d)

Brace

11.

Java is case sensitive language.

a)

True

b)

False

12.

how many values are required by unary operators

a)

Three

b)

One

c)

Two

13.

String values are always written in

a)

Single quotes

b)

without quotes

c)

Double quotes

14.

How many characters can be stored in a character data type?

a)

one

b)

two

c)

three

15.

Unary operators are used to increase or decrease only one number.

a)

true

b)

false

c)

none

16.

Which of the following loops will execute the body of loop even when condition controlling the loop is initially false?

a)

for

b)

while

c)

do..while

d)

None of the above

17.

What will be the output of the following program.

class WeekDays

{

public static void main(String s[])

{

int day = 4;

switch(day)

{

case 1:

System.out.println("Monday");

case 2:

System.out.println("Tuesday");

case 3:

System.out.println("Wednesday");

case 4:

System.out.println("Thursday");

case 5:

System.out.println("Friday");

default:

System.out.println("Weekend");

break;

}

}

}

a)

Thursday

b)

Compilation Error

c)

Thursday

Friday

Weekend

d)

Runtime error

18.
Boolean values are: 
a)
True / False
b)
Yes / No
c)
Right / Wrong
19.

T && T =

a)

T

b)

F

20.

T && F =

a)

T

b)

F

21.

F && F =

a)

T

b)

F

22.

F || F =

a)

T

b)

F

23.

F && T =

a)

T

b)

F

24.

T || F =

a)

T

b)

F

25.

F || T =

a)

T

b)

F

26.

!T =

a)

T

b)

F

27.

!T || T =

a)

T

b)

F

28.

!T && T =

a)

T

b)

F

29.

Is "X" printed?

a)

YES

b)

NO

30.

Is "X" printed?

a)

YES

b)

NO

31.

Click ALL answers which result in an "X" printed.

a)

a = 3, b = 3, c = 3

b)

a = 5, b = 4, c = 7

c)

a = 1, b = 3, c = 5

d)

a = 6, b = 4, c = 3

e)

a = 5, b = 5, c = 3

32.

What is output?

a)

Jackson

b)

Memorial

c)

JacksonMemorial

d)

There is no ouptut

33.

What is output?

a)

0

b)

1

c)

2

d)

3

34.

What is output?

a)

-1

b)

0

c)

1

d)

2

35.

What are the keywords used to implement a SWITCH case in Java language?

a)

switch, case

b)

default

c)

break

d)

All of above

36.

What is the output of Java program with SWITCH below?


int a=10;

switch(a)

{

case 10: System.out.println("TEN");

}

a)

No Output

b)

TEN

c)

Compiler error as there is no break

d)

None

37.

What is the output of the Java program below?


int b=20;

switch(b)

{

default: System.out.println("LION");

}

a)

No Output

b)

LION

c)

Compiler error as there are no CASE statements.

d)

None

38.

What is the output of Java program with SWITCH?


int num=20;

switch(num)

{

case 10: System.out.println("TEN"); break;

case 20: System.out.println("TWENTY"); break;

case 30: System.out.println("THIRTY");

}

a)

TEN

b)

TWENTY

c)

THIRTY

d)

TEN TWENTY

39.

What is the output of Java program below?


int num=40;

switch(num)

{

case 5: System.out.println("FIVE"); break;

case 35+5: System.out.println("FORTY"); break;

case 20+30: System.out.println("FIFTY");

}

a)

FIVE

b)

FORTY

c)

FIFTY

d)

Error

40.

What is the output of the below Java program?


switch(15)

{

case 5*2: System.out.println("TEN");break;

case 5*4-5:System.out.println("FIFTEEN");break;

case 60/4+5: System.out.println("TWENTY");

}

a)

TEN

b)

FIFTEEN

c)

TWENTY

d)

Error

41.

What does the following code segment print?

a)

5 4 3 2 1

b)

-5 -4 -3 -2 -1

c)

-4 -3 -2 -1 0

42.

Which Loop is repeating the action fixed number of times?

a)

For Loops

b)

While Loops

43.

Which of the following are true statements? (Choose all that apply)

a)

Java allows operator overloading.

b)

Java code compiled on Windows can run on Linux.

c)

Java has pointers to specific locations in memory.

d)

Java is a procedural language.

e)

Java is an object-oriented language

44.

Bitwise logical operators in Java work with?

a)

true/false boolean data

b)

0 and 1 individual bits of data

c)

Characters of a String

d)

none of the above

45.

What is the output of any Logical operation in Java?

a)

1 or 0

b)

true or false

c)

char or String

d)

None of the above

46.

Which is the Logical operator in Java that works with a Single Operand?

a)

AND

b)

OR

c)

EXOR

d)

NOT

47.

What is the output of the Java code snippet?

boolean b=false;

b = !b;

System.out.println(b);

a)

true

b)

false

c)

none of the above

d)

compilation error

48.

What is the result of 13<=13 ?

a)

True

b)

False

c)

Both true and false

d)

None

49.

What is the symbol of ternary operator?

a)

?:

b)

?;

c)

:?

d)

;?

50.

in Java every statement is end with _____?

a)

Comma

b)

Colon

c)

Semicolon

d)

Brace

51.

Which of the following operators can operate on a boolean variable?

1. &&

2. ==

3. ?:

4. +=

a)

3 & 2

b)

1 & 4

c)

1, 2 & 4

d)

1, 2 & 3

52.

Which of these have highest precedence?

a)

()

b)

++

c)

*

d)

>>

53.

What is the value stored in x in the following lines of Java code?

int x, y, z;

x = 0;

y = 1;

x = y = z = 8;

a)

0

b)

1

c)

9

d)

8

54.

What is the order of precedence (highest to lowest) of following operators?

1. &

2. ^

3. ?:

a)

1 -> 2 -> 3

b)

2 -> 1 -> 3

c)

3 -> 2 -> 1

d)

2 -> 3 -> 1

55.

float myFloatNum = 5.99f;

System.out.println(myFloatNum);


What will be the output?

a)

5.99

b)

5.99f

c)

"5.99"

d)

"5.99"f

56.

int x = 5;

int y = 6

int z = 50;

System.out.println(x + y + z);


What will be the output?

a)

61

b)

5650

c)

66

d)

x + y + z

57.

which of the following is NOT a primitive data type?

a)

byte

b)

array

c)

char

d)

boolean

58.

int sum1 = 100 + 50;

int sum2 = sum1 + 250;

int sum3 = sum2 + sum2;

System.out.println(sum3);


What will be the final output?

a)

950

b)

800

c)

sum2sum2

d)

sum1250

59.

int x = 10;

x = x + 5;

System.out.println(x);


What will be the output?

a)

15

b)

5

c)

55

d)

x5

60.

x /= 3


Which of the below statements matches with above statement?

a)

x = 3 / x

b)

x = x / 3

c)

x / 3

d)

x /x = 3

61.

int x = 4;

System.out.println(x < 5 && x < 10);


What will be the output?

a)

false

b)

true

c)

4

d)

x < 5 && x < 10

62.

int x = 4.4;

int y = 5.5;

System.out.println(x == y);


What will be the output?

a)

4.4

b)

true

c)

false

d)

5.5

63.

What is the output of below code?


int x = 5;

System.out.println(x++);

System.out.println(x);

a)

5

5

b)

6

6

c)

5

6

d)

6

5

64.

what is modulo operation used for ?

a)

performs division

b)

performs division and gives no remainder

c)

performs division and gives remainder

d)

does not perform division

65.

Find the output for the following.

public class IncDec

{

public static void main(String s[])

{

int a = 1;

int b = 2;

int c;

int d;


c = ++b;

d = a++;


c++;


System.out.println("a = " + a);

System.out.print("b = " + b);

System.out.println("c = " + c);

System.out.print("d = " + d);

}

}

a)

a = 2 b = 3 c = 4 d = 1

b)

a = 2 b = 3 c = 4 d = 1

c)

Program does not compile.

d)

a = 1 b = 2 c = 4 d = 2

66.

By default, Increment operator increments the variable’s value by ____

a)

1

b)

2

c)

3

d)

4

67.

Which of these is the correct way to name a variable?

a)

45632

b)

4variable

c)

player_Name

d)

player name

68.

int x= 1;

int y = 10;

int z = x % y;

System.out.println(z);

Guess the output.

a)

1

b)

10

c)

0

d)

-1

69.
Which operator is also called a ternary operator?
a)
logical
b)
arithmetic
c)
bitwise
d)
conditional
70.

Which of the following is incorrect?

a)

int count = 5o.0;

b)

int salary = 50_000;

c)

int salary = 50_00;

d)

all of these are incorrect

71.
What does a comment look like in Java?
a)
//comment
b)
\\comment
c)
==comment
d)
\comment
72.

Which function is used to input int value in Java using Scanner class?

a)

scanner_object . nextInteger( )

b)

scanner_object . nextInt( )

c)

scanner_object . nextint( )

d)

scanner_object . NextInt( )

73.

Which function is used to input float value in Java using Scanner class?

a)

scanner_object . nextFloat( )

b)

scanner_object . nextInt( )

c)

scanner_object . nextfloat( )

d)

scanner_object . NextFloat( )

74.

Which function is used to input String value in Java using Scanner class?

a)

scanner_object . nextLine( )

b)

scanner_object . nextString( )

c)

scanner_object . nextText( )

d)

scanner_object . nextChar( )

75.

Select TWO correct ways of including (importing) package in our program?

a)

import package_name . java . *;

b)

import java . package_name . *;

c)

include java . package_name . *;

d)

import java . package_name . Class_Name;

76.
a)

0

b)

10

c)

Compilation Error

d)

5-5

77.

What package is a part of the wrapper class which is imported by default into all Java programs?

a)

java.io

b)

java.util

c)

java.lang

d)

all the above

78.

Which method does not store string value after space?

a)

next()

b)

nextLine()

c)

nextString()

79.

Which is the correct syntax to declare Scanner class object?

a)

Scanner objectName= new Scanner(System.in);

b)

Scanner objectName= new Scanner();

c)

Scanner objectName= Scanner(System.in);

d)

Scanner objectName= Scanner();

80.

the operation performed on three variables belongs to which classification

a)

unary

b)

binary

c)

ternary

d)

all the above

81.

if(a>b)

System.out.println("a is big")

else

System.out.println("b is big");

what is output?

a)

a is big

b)

b is big

c)

error

d)

none of the above

82.

When we want to print in Java, we use the code ......

a)

system.out.print();

b)

System.out.println();

c)

System.Out.Printf();

d)

System.out.print();

83.

What is the output for the following statement:

System.out.print("1"+"1");

a)

11

b)

2

c)

Error Message

84.

Indicate the actual output of the statements below:

int thisYear = 2020;

System.out.println("The current year is "+thisYear);

a)

The current year is thisYear

b)

The current year is 2020

c)

No output; an error exists

d)

The current year is