Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Operators and Statements

Total questions: 60

Worksheet time: 45mins

Name
Class
Date
1.

Which of the following is NOT a data types in java

a)

int

b)

String

c)

number

d)

double

2.

What is right way of defining String variable?

a)

String name = "John";

b)

String name = "John"

c)

String name = John;

d)

String name "John";

3.

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

4.

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

5.

Based on, the general rules for constructing names for variables.

Pick false statement.

a)

Names can contain letters, digits, underscores, and dollar signs.

b)

Names are NOT case sensitive

c)

Reserved words (like Java keywords, such as int or String) cannot be used as names

d)

Names can also begin with $ and _

6.

Which of the following is NOT a NON-primitive data type

a)

String

b)

Array

c)

double

d)

class

7.

which of the following is NOT a primitive data type?

a)

byte

b)

array

c)

char

d)

boolean

8.

Which of the following is the right way of defining char variable?

a)

char myGrade = 'B';

b)

char myGrade = "B";

c)

char myGrade 'B';

d)

char myGrade = "B"

9.

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

10.

Which of the following is assignment operator?

a)

==

b)

=

c)

=+

d)

++

11.

int x = 10;

x = x + 5;

System.out.println(x);


What will be the output?

a)

15

b)

5

c)

55

d)

x5

12.

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

13.

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

14.

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

15.

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

16.

++ increases the value of a variable by 1

a)

assignment operator

b)

decrement operator

c)

increment operator

d)

sentinel

17.

--; decreases the value of a variable by 1

a)

assignment operator

b)

decrement operator

c)

increment operator

d)

sentinel

18.

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

19.

What would the new value of A be?

A=1;

a++;

a)

1

b)

2

c)

3

d)

4

20.

What would the new value of A be?

A=1;

A--;

a)

0

b)

1

c)

2

d)

-1

21.

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

22.

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

a)

true

b)

false

23.

What does the following code output?

int x = 1;

System.out.println(x++);

a)

1

b)

2

c)

compilation error

d)

runtime error

24.

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

a)

i += 1

b)

i++

c)

i -= 1

d)

i--

25.
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--;
26.

What's the value of below?


int i=5;


System.out.println(i);

System.out.println(++i);

a)

6

7

b)

67

c)

7

8

d)

5

6

27.

What symbol represents the and operator in Java?

a)

AND

b)

and

c)

&

d)

&&

28.

What symbol represents the or operator in Java?

a)

OR

b)

or

c)

||

d)

|

29.
Which one of the following is NOT a logical operator?
a)
||
b)
&&
c)
$$
d)
!
30.

If a=2, b=5, c=3

Find result for : 8 * (a + b + c) – a % c

a)

80

b)

81

c)

77

d)

78

31.

int a = 2, b = 2, c = 0;

double d = 30.1;


Find answer for = (a > b) &&(( c <d) || (c!=a))

a)

35.9

b)

80

c)

true

d)

false

32.

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

33.

arithmetic operators return a value. True or false?

a)

true

b)

false

34.

conditional operators does not return a value

a)

true

b)

false

35.

which data types work on bitwise operators?

a)

byte

b)

double

c)

char

d)

int

36.

which type of operator it is? i + =5

a)

addition assignment operator

b)

conditional operator

c)

arithmetic operator

d)

equality operator

37.

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

38.

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

39.

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

40.

Please write correct output in following space-

a)

10

b)

20

c)

No Output

d)

Error

41.

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

a)

bitwise operator

b)

subtraction operator

c)

equality operator

d)

arithmetic operator

42.

the values on which operations are performed are called operator. true or false?

a)

true

b)

false

43.

select as many unary arithmetic operators as you see

a)

==

b)

--

c)

||

d)

!

44.

a=11,b=22

solve= a +b + a++ + b++ + ++a + ++b

a)

103

b)

164

c)

87

d)

94

45.

binary arithmetic operators require two values

a)

true

b)

false

46.

which description of these relational operators are incorrect?

a)

==(equal to)

b)

<(less than)

c)

>=(greater than)

d)

!=(less than equal to)

47.

Concatenation(+)operator is used for joining two strings

a)

true

b)

false

48.

The operators used in Arithmetic expressions can be classified into

a)

Unary operator

b)

Binary operator

c)

Ternary operator

d)

All of the above

49.

The values involved in any mathematical operations are known as ____________

a)

Operators

b)

Operands

c)

Symbols

d)

Tokens

50.

__________ operator increases the value of the operand by 1.

a)

--

b)

-

c)

++

d)

+

51.

if p=10, then the output of the expression c= p++ *5 is

a)

50

b)

55

c)

45

d)

0

52.

if a = 30, then value of b = a--+--a

a)

b= 56

b)

b= 58

c)

b= 57

d)

b= 59

53.

Ternary operators are also called as

a)

increment operator

b)

decrement operator

c)

Conditional assignment

d)

none of the above

54.

The output of the following statements will be

int a = 14; b= 4;

boolean x=(a>b)? true:false

a)

true

b)

false

c)

error

d)

none of the above

55.

The return value of relational expressions and logical expressions is ________

a)

integer value

b)

decimal value

c)

boolean value

d)

none of the above

56.

&& operator will return true value only if both the relational expressions involved returns the value

a)

true

b)

false

c)

both

d)

none of the above

57.

In this expression the ________ logical operator that will be performed first _

((a>b)&&(b>c))||(b>a)!(c>b))

a)

&&

b)

||

c)

!

d)

?

58.

The return value of the expression

10<15 || 2>3||100>23 will be

a)

False

b)

True

c)

Yes

d)

No

59.

_________ operator is used to allocate space in the dynamic memory for storage of data.

a)

dot

b)

&

c)

new

d)

<<

60.

_________ operator facilitates invoking members of the class to carry out task.

a)

&

b)

|

c)

new

d)

dot