wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java Operators

Total questions: 129

Worksheet time: 2hrs 9mins

Name
Class
Date
1.

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

a)

i += 1

b)

i++

c)

i -= 1

d)

i--

2.

++ increases the value of a variable by 1

a)

assignment operator

b)

decrement operator

c)

increment operator

d)

sentinel

3.

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

4.

What would the new value of A be?

A=1;

a++;

a)

1

b)

2

c)

3

d)

4

5.

Please write correct output in following space-

a)

10

b)

20

c)

No Output

d)

Error

6.

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

7.

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

8.

Find the output of the following snippet.


class Numbers

{

public static void main(String args[])

{

int a=20, b=10;

if((a<b)&&(b++ <25))

{

System.out.println("this is any language logic");

}

System.out.println(b);

}

}

a)

10

b)

12

c)

11

d)

Compilation Error

9.

Which are the types of operators seen? Select as many you think

a)

bitwise operator

b)

subtraction operator

c)

equality operator

d)

arithmetic operator

10.

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

11.

arithmetic operators return a value. True or false?

a)

true

b)

false

12.

conditional operators does not return a value

a)

true

b)

false

13.

which data types work on bitwise operators?

a)

byte

b)

double

c)

char

d)

int

14.

which type of operator it is? i + =5

a)

addition assignment operator

b)

conditional operator

c)

arithmetic operator

d)

equality operator

15.

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

a)

operands

b)

variables

c)

operators

d)

Ternary

16.

Which are the types of operators seen? Select as many you think

a)

bitwise operator

b)

subtraction operator

c)

equality operator

d)

arithmetic operator

17.

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

a)

i += 1

b)

i++

c)

i -= 1

d)

i--

18.

++ increases the value of a variable by 1

a)

assignment operator

b)

decrement operator

c)

increment operator

d)

sentinel

19.

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

20.

What would the new value of A be?

A=1;

a++;

a)

1

b)

2

c)

3

d)

4

21.

Please write correct output in following space-

a)

10

b)

20

c)

No Output

d)

Error

22.

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

23.

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

24.

Find the output of the following snippet.


class Numbers

{

public static void main(String args[])

{

int a=20, b=10;

if((a<b)&&(b++ <25))

{

System.out.println("this is any language logic");

}

System.out.println(b);

}

}

a)

10

b)

12

c)

11

d)

Compilation Error

25.

Which are the types of operators seen? Select as many you think

a)

bitwise operator

b)

subtraction operator

c)

equality operator

d)

arithmetic operator

26.

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

27.

arithmetic operators return a value. True or false?

a)

true

b)

false

28.

conditional operators does not return a value

a)

true

b)

false

29.

which data types work on bitwise operators?

a)

byte

b)

double

c)

char

d)

int

30.

which type of operator it is? i + =5

a)

addition assignment operator

b)

conditional operator

c)

arithmetic operator

d)

equality operator

31.

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

a)

operands

b)

variables

c)

operators

d)

Ternary

32.

Choose the logical operators

a)

And

b)

Less than

c)

OR

d)

Not Equal

33.

What is the result of 13<=13 ?

a)

True

b)

False

c)

Both true and false

d)

None

34.

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

a)

True

b)

False

35.

What is the symbol of ternary operator?

a)

?:

b)

?;

c)

:?

d)

;?

36.

What is the value in variable A?

A+=112

a)

112

b)

111

c)

113

d)

130

37.

What is the another name of constant in java?

a)

Dynamic

b)

Static

c)

Literals

d)

Change

38.

in Java every statement is end with _____?

a)

Comma

b)

Colon

c)

Semicolon

d)

Brace

39.

Java is case sensitive language.

a)

True

b)

False

40.

Choose the correct statement about java?

a)

First name of a java is OAK

b)

Java is a advanced version of VB

c)

Java is the name of a Tree

d)

Java doesn't support object

41.

Java program can distributed over the internet by using _____

a)

Tablet

b)

Applet

c)

HTML

d)

Package

42.

++ increases the value of a variable by 1

a)

assignment operator

b)

decrement operator

c)

increment operator

d)

sentinel

43.
Which of the sets of statements below will add 1 to x if x is positive and subtract 1 from x if x is negative but leave x alone if x is 0?
a)
if (x > 0)  x++;
else x--;
b)
if (x > 0) x++;
else if (x < 0) x--;
c)
if (x > 0) x++;
if (x < 0) x--;
else x = 0;
d)
if (x == 0) x = 0;
else x++;
x--;
44.

++i and i++ cannot be used anywhere for the same purpose

a)

true

b)

false

45.

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

a)

i += 1

b)

i++

c)

i -= 1

d)

i--

46.

++ increases the value of a variable by 1

a)

assignment operator

b)

decrement operator

c)

increment operator

d)

sentinel

47.

--; decreases the value of a variable by 1

a)

assignment operator

b)

decrement operator

c)

increment operator

d)

sentinel

48.

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

49.

What would the new value of A be?

A=1;

A--;

a)

0

b)

1

c)

2

d)

-1

50.

What does the following code output?

int x = 1;

System.out.println(x++);

a)

1

b)

2

c)

compilation error

d)

runtime error

51.

PRE-increment us used when you want to use the incremented

value of the variable in that expression. Whereas POST-increment uses the original value before incrementing it

a)

True

b)

False

52.

What would the new value of A be?

A=1;

a++;

a)

1

b)

2

c)

3

d)

4

53.

Write the java expression for the following

ax5+bx3+c

(a)  

54.

Give the output of the following , when m = 10, n =6

m - = 9 % ++n + ++n/2

(a)  

55.

What is the value of y if x = 5

y = ++x - x++ + --x

(a)  

56.

a2+b\sqrt{a^2+b}



(a)  

57.

What will be the value x if a = , b =

x = ( a > b ) ? a : b

(a)  

58.

Rewrite the following code using ternary operator


int c ;

if( a > b )

c = a;

else

c = b;

(a)  

59.

Evaluate if a = 10 , b = 8

a % b++

(a)  

60.

What is the output of the following

char x = 'A' ;

int m ;

m = ( x== 'a') ? 'A' : 'a' ;

(a)  

61.

What will be the value of m if m = 8

m *= 8

(a)  

62.

Write the output of the following


( 4 > 7 ) || ( 7 < 15 )

a)

true

b)

false

63.

how many values are required by unary operators

a)

Three

b)

One

c)

Two

64.

The operator '==' checks for

a)

Equal values

b)

Greater values

c)

lesser values

65.

String values are always written in

a)

Single quotes

b)

without quotes

c)

Double quotes

66.

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

a)

one

b)

two

c)

three

67.

What is the difference between float and double data type?

4 lines
68.

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

a)

true

b)

false

c)

none

69.

true && true

a)

true

b)

false

70.

false == false

a)

true

b)

false

71.

true != true

a)

true

b)

false

72.

false || true

a)

true

b)

false

73.

false ^ false

a)

true

b)

false

74.

false && false

a)

true

b)

false

75.

true || true

a)

true

b)

false

76.

true ^ false

a)

true

b)

false

77.

true == false

a)

true

b)

false

78.

false != true

a)

true

b)

false

79.

Types of Java Operators

a)

logical

b)

arithmetic

c)

relational

d)

all of above

80.

Java expression

a<b

Types of operator for above expression is

a)

Relational

b)

logical

c)

arithmetic

81.

Evaluate this expression

a=3,b=4

!(a==0) && (b<5)

a)

true

b)

false

82.

Which of the following statement is valid

a)

int a+b=5;

b)

double char =m;

c)

int name;

name = 5;

d)

IQ = 5;

int IQ;

83.

Java expression

a&&b

Type of operator

a)

relational

b)

logical

c)

arithmetic

84.

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

85.

What will be the output of the following program?


public class DemoOnOperators

{

public static void main(String[] args)

{

int input = 7;

int output = ++input + ++input + ++input;

System.out.println(output);

}

}

a)

-20

b)

109

c)

27

d)

35

86.

What will be the output of the following program?


public class DayMonthDemo

{

public static void main(String args[])

{

int num = 69;

int days = num % 30;

int month = num / 30;

System.out.println(month + " Month and " + days + " days");

}

}

a)

3 Month and 9 days

b)

2 Month and 9 days

c)

0 Month and 69 days

d)

0 Month and 29 days

87.

Choose the incorrect statement about the following expressions?


a=a+1; // Expression 1

a++; // Expression 2

a+=1; // Expression 3

++a; // Expression 4

a)

All expressions give the same result

b)

'Expression 2' is faster that 'Expression 3' which inturn is faster than 'Expression 1'

c)

The value of 'a' after 'Expression 2' is different from 'Expression 4'

d)

The value of 'a' after 'Expression 1' is same as 'Expression 3

88.

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

89.

What is the output of the Java code snippet with Ternary operator?

String name = "java";

int marks = name == "java"?10:20;

System.out.println("Marks=" + marks);

a)

marks=0

b)

marks=10

c)

marks=20

d)

None of the above

90.

Find the output of the following snippet.


class Numbers

{

public static void main(String args[])

{

int a=20, b=10;

if((a<b)&&(b++ <25))

{

System.out.println("this is any language logic");

}

System.out.println(b);

}

}

a)

10

b)

12

c)

11

d)

Compilation Error

91.

It provides a runtime environment in which Java byte code can be executed

a)

JVM

b)

JDK

c)

JRE

d)

Eclipse IDE

92.

What does IDE mean?

a)

Integration Development Environment

b)

Integration Device Environment

93.

Which one is correct?

a)

public static main(Strings[] args) { }

b)

public private static main(Strings[] args) { }

c)

public static void main(Strings[] args) { }

d)

public void static main(Strings[] args) { }

94.

byte is 1 byte size in storage?

a)

True

b)

False

95.

Long is 4 byte size in storage?

a)

True

b)

False

96.

char is 2 byte in storage?

a)

True

b)

False

97.

(=) sign means

a)

equals and it is used for math problems in Java

b)

assignment operator. It used to assign a value

98.

Which one is used for remainder in Java?

a)

/

b)

%

c)

+

d)

*

99.

int x = 3; in this case, which of the following statement is true?

a)

x = x+1;

b)

x++;

c)

x += 1;

d)

All of above

100.

A developer wants to convert a smaller data type to larger data type. What is this in Java?

a)

Widening primitive

b)

Narrowing primitive

101.

Which data type is used to store:

TRUE

a)

Boolean

b)

Double

c)

String

d)

Integer

102.

Which data type is used to store:

100

a)

Integer

b)

Double

c)

Boolean

d)

String

103.
Which data type is used to store:
"D"
a)
Character
b)
String
c)
Integer
d)
Double
104.
This data type is used to store whole numbers
a)
Integer
b)
Double
c)
Boolean
d)
String
105.
This data type is used to store a mixture of letters and numbers and symbols.
a)
String
b)
Character
c)
Boolean
d)
Integer
106.

What is a variable?

a)

A storage location of memory which can change

b)

A random area to store things in.

c)

Something that changes

d)

Something that can only store numbers

107.
What data type would be best used to record the number of people at a party?
a)
Integer
b)
Real
c)
String
d)
Boolean
108.
Integers cannot store negative numbers.
a)
False
b)
True
109.
What data type would be best used to record an email address?
a)
String
b)
Integer
c)
Real
d)
Character
110.
Expressions cannot contain variables of different data types.
a)
False
b)
True
111.
Data types of variables can never be changed.
a)
False
b)
True
112.

It provides a runtime environment in which Java byte code can be executed

a)

JVM

b)

JDK

c)

JRE

d)

Eclipse IDE

113.

Which one is correct?

a)

public static main(Strings[] args) { }

b)

public private static main(Strings[] args) { }

c)

public static void main(Strings[] args) { }

d)

public void static main(Strings[] args) { }

114.

char is 2 byte in storage?

a)

True

b)

False

115.

(=) sign means

a)

equals and it is used for math problems in Java

b)

assignment operator. It used to assign a value

116.

int x = 3; in this case, which of the following statement is true?

a)

x = x+1;

b)

x++;

c)

x += 1;

d)

All of above

117.

Which one is used for remainder in Java?

a)

/

b)

%

c)

+

d)

*

118.

Which component is used to compile, debug and execute java program?

a)

JVM

b)

JDK

c)

JIT

d)

JRE

119.

Which component is responsible for converting bytecode into machine specific code?

a)

JVM

b)

JDK

c)

JIT

d)

JRE

120.

Which component is responsible to run java program?

a)

JRE

b)

JVM

c)

JIT

d)

JDK

121.

Which component is responsible to optimize bytecode to machine code?

a)

JRE

b)

JVM

c)

JDK

d)

JIT

122.

Which statement is true about java?

a)

Sequence dependent programming language

b)

Code dependent programming language

c)

Platform independent programming language

d)

Platform dependent programming language

123.

JVM is _____

a)

code dependent

b)

code independent

c)

platform dependent

d)

platform independent

124.

What is the extension of compiled java classes?

a)

.class

b)

.js

c)

.txt

d)

.java

125.

Which of the following option leads to the portability and security of Java?

a)

The applet makes the Java code secure and portable

b)

Use of exception handling

c)

Dynamic binding between objects

d)

Bytecode is executed by JVM

126.

Which of the following is not a Java features?

a)

Architecture Neutral

b)

Dynamic

c)

Use of pointers

d)

Object-oriented

127.

In which memory a String is stored, when we create a string using new operator?

a)

Stack

b)

String memory

c)

Random storage space

d)

Heap memory

128.

correct execution process in Java

a)

load->edit->compile->verify->execute

b)

edit->load->compile->execute->verify

c)

edit->compile->load->verify->execute

d)

verify->edit->compile->load->execute

129.

JVM full form___

a)

Java Visual Model

b)

Java Virtual Model

c)

Java Visual Machine

d)

Java Virtual Machine