Question: 1 -
Which statement is true?public class While
{
public void loop()
{
int x= 0;
while ( 1 ) /* Line 6 */
{
System.out.print("x plus one is " + (x + 1)); /* Line 8 */
}
}
}
-
There are syntax errors on lines 1, 6, and 8.
-
There is a syntax error on line 6.
-
There are syntax errors on lines 1 and 6.
-
There is a syntax error on line 1.
Answer:
There is a syntax error on line 6.
Solution not available.
Question: 2 -
Which two are acceptable types for x?switch(x)
{
default:
System.out.println("Hello");
}
-
short
-
long
-
float
-
char
Answer:
short
Solution not available.
Question: 3 -
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);
-
No output
-
Error
-
25
-
15
Answer:
15
Solution not available.
Question: 4 -
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);
-
No output
-
Error
-
x is 15
-
y is 20
Answer:
x is 15
Solution not available.
Question: 5 -
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");
}
}
-
"odd" will be output for odd values of x, and "even" for even values.
-
"odd" will always be output.
-
"even" will always be output.
-
Compilation fails.
Answer:
Compilation fails.
Solution:
The compiler will complain because of incompatible types (line 4), the if expects a boolean but it gets an integer.
The compiler will complain because of incompatible types (line 4), the if expects a boolean but it gets an integer.