Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
5 views

Java Conditions Test

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Java Conditions Test

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Prepared

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

7. What will be the output of the following Java


program?

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");

} run time Hello compile compile


8 } Hello error world time error time error

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.

The next The next


case block case block
will be will be
executed The executed
In a switch-case statement, what happens if The regardless of program will regardless of
there is no “break” statement after a case program will Runtime the enter in an the
13 block? not compile. error. condition. infinite loop. condition.
Which control statement is used to exit from a
14 loop or switch-case statement prematurely? continue exit terminate break break
The loop
will produce
The loop The loop The loop a The loop
In a “for” loop, what happens if the update will not will enter an will execute compilation will execute
15 statement is missing? execute. infinite loop. only once. error. only once.
16
The conditional statement, ………………. can
only test for equality, whereas ………………. can
17 evaluate any type of Boolean expression. if, switch switch, if while, if if, while if, switch
What will be the output of the following code
snippet?

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

What will be the output of the following code?

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

You might also like