WorksheetsOperators and Statements
Total questions: 60
Worksheet time: 45mins
Which of the following is NOT a data types in java
int
String
number
double
What is right way of defining String variable?
String name = "John";
String name = "John"
String name = John;
String name "John";
int x = 5;
int y = 6
int z = 50;
System.out.println(x + y + z);
What will be the output?
61
5650
66
x + y + z
float myFloatNum = 5.99f;
System.out.println(myFloatNum);
What will be the output?
5.99
5.99f
"5.99"
"5.99"f
Based on, the general rules for constructing names for variables.
Pick false statement.
Names can contain letters, digits, underscores, and dollar signs.
Names are NOT case sensitive
Reserved words (like Java keywords, such as int or String) cannot be used as names
Names can also begin with $ and _
Which of the following is NOT a NON-primitive data type
String
Array
double
class
which of the following is NOT a primitive data type?
byte
array
char
boolean
Which of the following is the right way of defining char variable?
char myGrade = 'B';
char myGrade = "B";
char myGrade 'B';
char myGrade = "B"
int sum1 = 100 + 50;
int sum2 = sum1 + 250;
int sum3 = sum2 + sum2;
System.out.println(sum3);
What will be the final output?
950
800
sum2sum2
sum1250
Which of the following is assignment operator?
==
=
=+
++
int x = 10;
x = x + 5;
System.out.println(x);
What will be the output?
15
5
55
x5
x /= 3
Which of the below statements matches with above statement?
x = 3 / x
x = x / 3
x / 3
x /x = 3
int x = 4;
System.out.println(x < 5 && x < 10);
What will be the output?
false
true
4
x < 5 && x < 10
int x = 4.4;
int y = 5.5;
System.out.println(x == y);
What will be the output?
4.4
true
false
5.5
What is the output of below code?
int x = 5;
System.out.println(x++);
System.out.println(x);
5
5
6
6
5
6
6
5
++ increases the value of a variable by 1
assignment operator
decrement operator
increment operator
sentinel
--; decreases the value of a variable by 1
assignment operator
decrement operator
increment operator
sentinel
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
True
False
What would the new value of A be?
A=1;
a++;
1
2
3
4
What would the new value of A be?
A=1;
A--;
0
1
2
-1
What's the value of below?
int i=5;
System.out.println(i++);
System.out.println(i);
System.out.println(++i);
5
6
7
6
6
7
6
7
8
5
5
6
++i and i++ cannot be used anywhere for the same purpose
true
false
What does the following code output?
int x = 1;
System.out.println(x++);
1
2
compilation error
runtime error
Which statement(s) are equivalent to i = i + 1?
i += 1
i++
i -= 1
i--
else x--;
else if (x < 0) x--;
if (x < 0) x--;
else x = 0;
else x++;
x--;
What's the value of below?
int i=5;
System.out.println(i);
System.out.println(++i);
6
7
67
7
8
5
6
What symbol represents the and operator in Java?
AND
and
&
&&
What symbol represents the or operator in Java?
OR
or
||
|
If a=2, b=5, c=3
Find result for : 8 * (a + b + c) – a % c
80
81
77
78
int a = 2, b = 2, c = 0;
double d = 30.1;
Find answer for = (a > b) &&(( c <d) || (c!=a))
35.9
80
true
false
what is modulo operation used for ?
performs division
performs division and gives no remainder
performs division and gives remainder
does not perform division
arithmetic operators return a value. True or false?
true
false
conditional operators does not return a value
true
false
which data types work on bitwise operators?
byte
double
char
int
which type of operator it is? i + =5
addition assignment operator
conditional operator
arithmetic operator
equality operator
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 = 2 b = 3 c = 4 d = 1
a = 2 b = 3 c = 4 d = 1
Program does not compile.
a = 1 b = 2 c = 4 d = 2
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);
}
}
small
tiny
huge
Compilation fails
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);
}
}
10
12
11
Compilation Error
Please write correct output in following space-
10
20
No Output
Error
Which are the types of operators seen? Select as many you think
bitwise operator
subtraction operator
equality operator
arithmetic operator
the values on which operations are performed are called operator. true or false?
true
false
select as many unary arithmetic operators as you see
==
--
||
!
a=11,b=22
solve= a +b + a++ + b++ + ++a + ++b
103
164
87
94
binary arithmetic operators require two values
true
false
which description of these relational operators are incorrect?
==(equal to)
<(less than)
>=(greater than)
!=(less than equal to)
Concatenation(+)operator is used for joining two strings
true
false
The operators used in Arithmetic expressions can be classified into
Unary operator
Binary operator
Ternary operator
All of the above
The values involved in any mathematical operations are known as ____________
Operators
Operands
Symbols
Tokens
__________ operator increases the value of the operand by 1.
--
-
++
+
if p=10, then the output of the expression c= p++ *5 is
50
55
45
0
if a = 30, then value of b = a--+--a
b= 56
b= 58
b= 57
b= 59
Ternary operators are also called as
increment operator
decrement operator
Conditional assignment
none of the above
The output of the following statements will be
int a = 14; b= 4;
boolean x=(a>b)? true:false
true
false
error
none of the above
The return value of relational expressions and logical expressions is ________
integer value
decimal value
boolean value
none of the above
&& operator will return true value only if both the relational expressions involved returns the value
true
false
both
none of the above
In this expression the ________ logical operator that will be performed first _
((a>b)&&(b>c))||(b>a)!(c>b))
&&
||
!
?
The return value of the expression
10<15 || 2>3||100>23 will be
False
True
Yes
No
_________ operator is used to allocate space in the dynamic memory for storage of data.
dot
&
new
<<
_________ operator facilitates invoking members of the class to carry out task.
&
|
new
dot
