Java Conditions Test
Java Conditions Test
Course Title by
Asghar
Programming in Java Pasha
Correct
Sl. No. Question A B C D Answer
Which of these selection statements test only none of the
1 for equality? if switch if & switch mentioned if
Which of these are selection statements in
2 Java? if() for() continue break continue
Which of the following loops will execute the
body of loop even when condition controlling none of the
3 the loop is initially false? do-while while for mentioned do-while
Which of these jump statements can skip
processing the remainder of the code in its
4 body for a particular iteration? break return exit continue continue
switch
statement
can only test
two case for equality,
switch constants in whereas if it is switch
statement is the same statement possible to statement is
more switch can can evaluate create a more
efficient than have any type of nested efficient
a set of identical boolean switch than a set of
5 Which of this statement is incorrect? nested ifs values expression statements nested ifs
What will be the output of the following Java
program?
class selection_statements
{
public static void main(String args[])
{
int var1 = 5;
int var2 = 6;
if ((var2 = 1) == var1)
System.out.print(var2);
else
System.out.print(++var2);
}
6 } 1 2 3 4 2
class comma_operator
{
public static void main(String args[])
{
int sum = 0;
for (int i = 0, j = 0; i < 5 & j < 5; ++i, j =
i + 1)
sum += i;
System.out.println(sum);
} compilation
7 } 5 6 14 error 6
What will be the output of the following Java
program?
class Output
{
public static void main(String args[])
{
final int a=10,b=20;
while(a<
{
System.out.println("Hello");
}
System.out.println("World");
class Output
{
public static void main(String args[])
{
int a = 5;
int b = 10;
first:
{
second:
{
third:
{
if (a == b >> 1)
break second;
}
System.out.println(a);
}
System.out.println( ;
}
}
9 } 5 10 10 5 5 10 10
To control To control
To perform the flow of the flow of
What is the purpose of control statements in mathematical To create To declare execution in execution in
10 Java? calculations objects variables a program a program
Which statement is used to terminate the
current iteration of a loop and continue with
11 the next iteration? break return continue exit continue
It is It is
executed executed
when none when none
It specifies It is used to of the cases of the cases
the default compare the match the match the
What is the purpose of the “default” case in a value of the value of the value of the None of value of the
12 switch statement? expression. expression. expression. these. expression.
int a=15;
int b=25;
if ((a< || (a=5)>15)
system.out.println(a);
else
18 system.out.println( ; Error 15 25 No output Error
int x, y;
x=15; y=20;
if (x>15)
if(y>15)
{
system.ptintln("y is "+y);
}
else
19 system.out.ptintln("x is "+x); Error y is 20 x is 15 No output x is 15
In the while and do-while loops, a …………………
statement causes control to be transferred
directly to the conditional expression that
20 controls the loop. break pause start continue continue