Java Programming Multiple Choice Questions - Control Flow Statements

This section focuses on the "Control Flow Statements" of the Java programming. These Multiple Choice Questions (mcq) should be practiced to improve the Java programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.

1. What will be the output of the following code snippet?
int a=15;
int b=25;
if ((a < b ) || ( a = 5)>15)
system.out.println(a);
else
system.out.println(b);

A. Error
B. 15
C. 25
D. No output

View Answer


2. What will be the output of the program?
int x, y;
x=15; y=20;
if (x>15)
if(y>15)
{
system.ptintln(“y is “+y);
}
else
system.out.ptintln(“x is “+x);

A. Error
B. y is 20
C. x is 15
D. No output

View Answer


3.Which two are acceptable types for x?
switch(x)
{
default:
System.out.println("Hello");
}

A. short
B. char
C. long
D. float

View Answer


4.Which statement is true?
public void test(int x)
{
int odd = 1;
if(odd) /* Line 4 */
{
System.out.println("odd");
}
else
{
System.out.println("even");
}
}

A. Compilation fails.
B. "odd" will always be output.
C. "even" will always be output.
D. "odd" will be output for odd values of x, and "even" for even values.

View Answer


5.public class While
{
public void loop()
{
int x= 0;
while ( 1 ) /* Line 6 */
{
System.out.print("x plus one is " + (x + 1)); /* Line 8 */
}
}
}
Which statement is true?

A. There is a syntax error on line 1.
B. There are syntax errors on lines 1 and 6.
C. There are syntax errors on lines 1, 6, and 8.
D. There is a syntax error on line 6.

View Answer







Also check :


Discussion


* You must be logged in to add comment.