Java MCQ Set-3 : Multiple Choice Questions in Java Set-3

Set-5 Java MCQ

1. Predict the output produced by the following code:

int I =0;
outer:
while (true)
{
I ++;
inner :
for(int j = 0; j<10; j++)
{
I+ = j;
continue inner r;
break outer;
}
continue outer;
}
System.out.println(I);

a. 0
b. 1
c. 2
d. 5

Answer : b)


2. State the output of the following code:

int a = 10, b=5;
if(a>b)
{
if(b>5)
System.out.println(“b is”+ b);
}
else
System.out.println(“a is”+ a);

a. 5
b. 10
c. No Output
d. 8

Answer : c)


3. Give the output of the following code:

int m = 100;
while (true)
{
if(m<10)
continue
m = m-10;
}
System.out.println(“m is”+ m);

a. 8
b. 7
c. 5
d. No output; Infinite loop

Answer : d)


4. Give the output of the following code:

int m = 100;
while (true)
{
if(m<10)
break;
m = m-10;
}
System.out.println(“m is”+ m);

a. 0
b. 1
c. 2
d. 3

Answer : a)


5. Predict the output of the following program:

class q5
{
public static void main (String args [])
{
int count = 0;
for (int i = 0; i<3; i++)
resume:
for (int j = 0; j<4; j++)
for (int k = 0; k<5; k++)
++count;
if((i = =1) && (j = =2) &&(k = =3)) break resume;
}
System.out.println(“\t count =”+ count);
}
}

a. 41
b. 54
c. 57
d. 60

Answer : b)


6. What is the output of the following code:

int f = 1, I = 2;
while (++i < 5)
f * = i;
System.out.println(f);

a. 6
b. 8
c. 10
d. 12

Answer : d)


7. What is the output of the following code:

int f = 1, i = 2;
do
{
f * = i;
}
while (++i < 5)
System.out.println(f);

a. 9
b. 15
c. 24
d. 27

Answer : c)
Java MCQ Set-3 Explanation


8. State the final value of q at the end of the following program segment:

int m, n, p, q = 0;
for (m = 2; m<=3; ++m)
{
for (n = 1; n<= m; ++n)
{
p= m+n-1;
if(p%3 = = 0 )
q+= p;
else
q+= p+4;
}
}

a. 29
b. 28
c. 58
d. 45

Answer : a)
Java MCQ Set-3 Explanation


9. Which stream is used for performing IO in Text Files?

a. FileInputStream
b. File Reader
c. FileOutputStream
d. DataInputStream

Answer : b)


10. Which stream is used for performing IO in binary Files?

a. FileWriter
b. BufferedReader
c. BufferedWriter
d. DataOutputStream

Answer : d)


Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *