Jav
NOTE :
1) Please don’t change any column name which is present by default.
2) In Correct Answer Column, Just insert the option number which is correct. (F
S. No. Question
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);
}
1 }
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);
}
2 }
What will be the output of the following Java program?
class jump_statments
{
public static void main(String args[])
{
int x = 2;
int y = 0;
for ( ; y < 10; ++y)
{
if (y % x == 0)
continue;
else if (y == 8)
break;
else
System.out.print(y + " ");
}
}
3 }
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<b)
{
System.out.println("Hello");
}
System.out.println("World");
}
4}
What will be the output of the following Java program?
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(b);
}
}
5 }
What would be the output of the following code snippet if variable
a=10?
if(a<=0)
{
if(a==0)
{
System.out.println("1 ");
}
else
{
System.out.println("2 ");
}
}
6 System.out.println("3 ");
7 The while loop repeats a set of code while the condition is not met
8 What is true about a break?
9 Which of the following is used with the switch statement?
What will be the output of following program?
public class temp
{
public static void main(String agrs[])
{
for(int i=1; i<=10; i++);
System.out.print(i);
}
10 }
What will be the output of following program?
public class temp
{
public static void main(String agrs[])
{
int i;
for(i=1; i<=10; i++);
System.out.print(i);
}
11 }
What will be the output of following program?
public class temp
{
public static void main(String agrs[])
{
int x[]={1,2,3,4,5};
for(int i=0; i<x.length;i++)
System.out.print(x[i]);
}
12 }
what will be the output of the following program?
public
class Test {
public
static void main(String[] args)
{
for (int i = 0; i < 10; i++)
int x = 10;
}
13 }
what will be the output of the following program?
public
class Test {
public
static void main(String[] args)
{
for (int i = 0, String = "GFG"; i < 2; i++)
System.out.println("HELLO GEEKS");
}
14 }
How many times 'Hello' is printed?
public class CppBuzz {
public static void main(String[] args){
for(int i = 0; i<5; i++)
{
System.out.println("Hello");
break;
}
}
15 }
How many times 'Hello' is printed?
public class CppBuzz {
public static void main(String[] args){
for(int i = 0; i<5; i++)
{
System.out.println("Hello");
i++;
}
}
16 }
How many times 'Hello' is printed?
public class CppBuzz {
public static void main(String[] args){
for(int i = 0; i<5; i++)
{
System.out.println("Hello");
i++;
i--;
}
}
}
17
How many times 'Hello' is printed?
public class CppBuzz {
public static void main(String[] args){
for(int i = 0; i<5; i++)
{
System.out.println("Hello");
i+=2;
}
}
18 }
public class CppBuzz {
public static void main(String[] args){
for(int i = 0; i<5; i+=2)
{
System.out.println("Hello");
i+=2;
}
}
19 }
How many times 'Hello' is printed?
public class CppBuzz {
public static void main(String[] args){
for(int i = 0; i<5; )
{
System.out.println("Hello");
}
}
20 }
How many times 'Hello' is printed?
public class CppBuzz {
public static void main(String[] args){
for(int i = 0; i>5; )
{
System.out.println("Hello");
}
}
}
21
How many times 'Hello' is printed?
public class CppBuzz {
public static void main(String[] args){
for(int i = 0; i<5; i=5 )
{
System.out.println("Hello");
}
}
22 }
import java.util.Scanner;
public class ExampleIfElse {
public static void main(String[] args){
String s = "friends";
int x = 0;
do {
System.out.print(s.charAt(x));
x++ ;
} while (x < 2);
23 }
How many times 'cppbuzz' is printed?
public class Main
{
public static void main(String[] args) {
while(true){
System.out.println("cppbuzz");
}
}
24 }
How many times 'cppbuzz' is printed?
public class Main
{
public static void main(String[] args) {
while(false){
System.out.println("cppbuzz");
}
}
25 }
How many time 'cppbuzz' is printed?
public class Main
{
public static void main(String[] args) {
while(true);{
System.out.println("cppbuzz");
}
}
26 }
How many times 'facebook' is printed?
public class Main
{
public static void main(String[] args) {
for(int i = 0; i<5; i++);
{
System.out.println("facebook");
}
}
27 }
How many times 'cppbuzz' is printed?
public class Main
{
public static void main(String[] args) {
do{
System.out.println("cppbuzz");
}while(false);
}
}
28
public class CppBuzz{
public static void main(String[] args){
int a = 0;
a +=5;
switch(a){
case 5: System.out.print("5");
case 10: System.out.print("10");
default: System.out.print("0");
}
29 }
public class CppBuzz{
public static void main(String[] args){
int a = 0;
a +=5;
switch(a){
case 5: System.out.print("5");
case 10: System.out.print("10");break;
default: System.out.print("0");
}
30 }
Java Control Statements
by default.
r which is correct. (For e.g. If Option 2 is correct answer then please enter 2)
Option 1 Option 2 Option 3
1 2 3
5 6 14
1357 2468 13579
Hello run time error Hello world
5 10 10 5 5
1 2 2 3 1 3
1 0 God Only Knows
Break stops the execution Break halts the execution aBreak forces the control out
Continue Exit break
12345678910 11 Error
12345678910 11 Error
Error 6 1,2,3,4,5
No Output 10 Compilation Error
HELLO GEEKS, HELLO
HELLO GEEKS Compile time error GEEKS,HELLO GEEKS
5 4 1
5 4 3
5 4 3
1 2 3
0 1 2
0 1 2
5 4 3
5 4 2
friends friend fr
1 2 Compilation Error
0 1 infinite loop
0 1 infinite loop
0 4 2
0 1 infinite loop
5 510 5100
5 10 510
Option 4 Correct Answer
4 2
Compilation Error 2
123456789 3
compile time error 4
10 4
3 4
None of the above 1
Break halts the execution o 2
do 3
1 2 3 4 5 6 7 8 9 10 3
1 2 3 4 5 6 7 8 9 10 2
12345 4
10( 10 times ) 3
no output 2
0 3
2 3
2 1
4 2
3 3
infinite 4
0 4
1 4
Compilation Error 3
infinite loop 4
Error 4
Error-unreachable stateme 4
1 4
error 2
Compilation Error 3
compilation Error 3