WorksheetsJava Operator and Control Flow Statement Test
Total questions: 84
Worksheet time: 2hrs 6mins
++ increases the value of a variable by 1
assignment operator
decrement operator
increment operator
sentinel
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
Which statement(s) are equivalent to i = i + 1?
i += 1
i++
i -= 1
i--
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
Please write correct output in following space-
10
20
No Output
Error
--------- is a symbol, that operates on operands and produce a result
operands
variables
operators
Ternary
Choose the logical operators
And
Less than
OR
Not Equal
The result of AND operator is always true, if both the conditions results are _____
True
False
What is the value in variable A?
A+=112
112
111
113
130
in Java every statement is end with _____?
Comma
Colon
Semicolon
Brace
Java is case sensitive language.
True
False
how many values are required by unary operators
Three
One
Two
String values are always written in
Single quotes
without quotes
Double quotes
How many characters can be stored in a character data type?
one
two
three
Unary operators are used to increase or decrease only one number.
true
false
none
Which of the following loops will execute the body of loop even when condition controlling the loop is initially false?
for
while
do..while
None of the above
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;
}
}
}
Thursday
Compilation Error
Thursday
Friday
Weekend
Runtime error
T && T =
T
F
T && F =
T
F
F && F =
T
F
F || F =
T
F
F && T =
T
F
T || F =
T
F
F || T =
T
F
!T =
T
F
!T || T =
T
F
!T && T =
T
F
Is "X" printed?
YES
NO
Is "X" printed?
YES
NO
Click ALL answers which result in an "X" printed.
a = 3, b = 3, c = 3
a = 5, b = 4, c = 7
a = 1, b = 3, c = 5
a = 6, b = 4, c = 3
a = 5, b = 5, c = 3
What is output?
Jackson
Memorial
JacksonMemorial
There is no ouptut
What is output?
0
1
2
3
What is output?
-1
0
1
2
What are the keywords used to implement a SWITCH case in Java language?
switch, case
default
break
All of above
What is the output of Java program with SWITCH below?
int a=10;
switch(a)
{
case 10: System.out.println("TEN");
}
No Output
TEN
Compiler error as there is no break
None
What is the output of the Java program below?
int b=20;
switch(b)
{
default: System.out.println("LION");
}
No Output
LION
Compiler error as there are no CASE statements.
None
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");
}
TEN
TWENTY
THIRTY
TEN TWENTY
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");
}
FIVE
FORTY
FIFTY
Error
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");
}
TEN
FIFTEEN
TWENTY
Error
What does the following code segment print?
5 4 3 2 1
-5 -4 -3 -2 -1
-4 -3 -2 -1 0
Which Loop is repeating the action fixed number of times?
For Loops
While Loops
Which of the following are true statements? (Choose all that apply)
Java allows operator overloading.
Java code compiled on Windows can run on Linux.
Java has pointers to specific locations in memory.
Java is a procedural language.
Java is an object-oriented language
Bitwise logical operators in Java work with?
true/false boolean data
0 and 1 individual bits of data
Characters of a String
none of the above
What is the output of any Logical operation in Java?
1 or 0
true or false
char or String
None of the above
Which is the Logical operator in Java that works with a Single Operand?
AND
OR
EXOR
NOT
What is the output of the Java code snippet?
boolean b=false;
b = !b;
System.out.println(b);
true
false
none of the above
compilation error
What is the result of 13<=13 ?
True
False
Both true and false
None
What is the symbol of ternary operator?
?:
?;
:?
;?
in Java every statement is end with _____?
Comma
Colon
Semicolon
Brace
Which of the following operators can operate on a boolean variable?
1. &&
2. ==
3. ?:
4. +=
3 & 2
1 & 4
1, 2 & 4
1, 2 & 3
Which of these have highest precedence?
()
++
*
>>
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;
0
1
9
8
What is the order of precedence (highest to lowest) of following operators?
1. &
2. ^
3. ?:
1 -> 2 -> 3
2 -> 1 -> 3
3 -> 2 -> 1
2 -> 3 -> 1
float myFloatNum = 5.99f;
System.out.println(myFloatNum);
What will be the output?
5.99
5.99f
"5.99"
"5.99"f
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
which of the following is NOT a primitive data type?
byte
array
char
boolean
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
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
what is modulo operation used for ?
performs division
performs division and gives no remainder
performs division and gives remainder
does not perform division
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
By default, Increment operator increments the variable’s value by ____
1
2
3
4
Which of these is the correct way to name a variable?
45632
4variable
player_Name
player name
int x= 1;
int y = 10;
int z = x % y;
System.out.println(z);
Guess the output.
1
10
0
-1
Which of the following is incorrect?
int count = 5o.0;
int salary = 50_000;
int salary = 50_00;
all of these are incorrect
Which function is used to input int value in Java using Scanner class?
scanner_object . nextInteger( )
scanner_object . nextInt( )
scanner_object . nextint( )
scanner_object . NextInt( )
Which function is used to input float value in Java using Scanner class?
scanner_object . nextFloat( )
scanner_object . nextInt( )
scanner_object . nextfloat( )
scanner_object . NextFloat( )
Which function is used to input String value in Java using Scanner class?
scanner_object . nextLine( )
scanner_object . nextString( )
scanner_object . nextText( )
scanner_object . nextChar( )
Select TWO correct ways of including (importing) package in our program?
import package_name . java . *;
import java . package_name . *;
include java . package_name . *;
import java . package_name . Class_Name;
0
10
Compilation Error
5-5
What package is a part of the wrapper class which is imported by default into all Java programs?
java.io
java.util
java.lang
all the above
Which method does not store string value after space?
next()
nextLine()
nextString()
Which is the correct syntax to declare Scanner class object?
Scanner objectName= new Scanner(System.in);
Scanner objectName= new Scanner();
Scanner objectName= Scanner(System.in);
Scanner objectName= Scanner();
the operation performed on three variables belongs to which classification
unary
binary
ternary
all the above
if(a>b)
System.out.println("a is big")
else
System.out.println("b is big");
what is output?
a is big
b is big
error
none of the above
When we want to print in Java, we use the code ......
system.out.print();
System.out.println();
System.Out.Printf();
System.out.print();
What is the output for the following statement:
System.out.print("1"+"1");
11
2
Error Message
Indicate the actual output of the statements below:
int thisYear = 2020;
System.out.println("The current year is "+thisYear);
The current year is thisYear
The current year is 2020
No output; an error exists
The current year is
