0% found this document useful (0 votes)
59 views

Core Java Quiz 1

This document contains 20 code snippets in Java with questions about the output. The code snippets cover topics like loops, operators, conditional statements, strings, and exceptions. For each code snippet, there is a multiple choice question about what would be printed or the error that would occur when running the code.

Uploaded by

Thilagavathi S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views

Core Java Quiz 1

This document contains 20 code snippets in Java with questions about the output. The code snippets cover topics like loops, operators, conditional statements, strings, and exceptions. For each code snippet, there is a multiple choice question about what would be printed or the error that would occur when running the code.

Uploaded by

Thilagavathi S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 23

Core Java Quiz 1

public class valan {


public static void main(String args[]) {
int odd = 10 % 2;
if(odd)
{
System.out.println("odd");
}
else
{
System.out.println("even");
}
} Compile time Error
}
What will be the output
public class valan{
public static void main(String args[]) {
while(1)
{
System.out.println("hai");
}

}
} Compile time Error
What will be the output
public class valan {
public static void main(String args[]) {
float f=3.14f;
switch(f)
{
case 3.14:
System.out.println("A");
break;
default:
System.out.println("B");
}

} Compile time Error


}
What will be the output
public class valan{
public static void main(String args[]) {
int a=1;
switch(a)
{
default:
System.out.println("B");
break;
case 1:
System.out.println("A");
break;
}
} A
}
What will be the output
public class valan {
public static void main(String argv[]) {
int a=1;
switch(a)
{
case 1:
System.out.print("A");
case 2:
System.out.print("B");
case 3:
System.out.print("C");
default:
System.out.print("D");
}
} ABCD
}
What will be the output
public class NewClass {
public static void main(String argv[]) {
int a=1;
switch(a)
{
default:
System.out.print("D");
case 1:
System.out.print("A");
case 2:
System.out.print("B");
case 3:
System.out.print("C");
}
}
ABC
}
What will be the output

public class NewClass {


public static void main(String argv[]) {
int i=1;
do while(i<1)
System.out.println("Hai");
while(i>1);
}
}
Nothing will Print
What will be the output

public class valan{


static boolean b1,b2;
public static void main(String [] args) {
b1=!b2;
System.out.println(b1+" "+b2);
}
}
true false
What will be the output of the program?

class Equals
{
public static void main(String [] args)
{
int x = 100;
double y = 100.1;
boolean b = (x = y);
System.out.println(b);
} Compile time Error
}
What will be the output

class Test
{
public static void main(String [] args)
{
int x=20;
String sup = (x < 15) ? "small" : (x < 22)?
"tiny" :"huge";
System.out.println(sup);
}
tiny
}
What will be the output

public class valan {


public static void main(String[] args) {
System.out.println(10+20);
System.out.println("10"+20);
System.out.println("10"+20+30);
}
}
30
1020
102030
What will be the output
public class valan {

public static void main(String[] args) {


int a=10;
int c=++a + a++ +a;
System.out.println(c);
}

}
34
public class valan{
public static void main(String args[]){
System.out.println(0.0==-0.0);

}
}

true
public class valan {
public static void main(String args[]){
for(int i=0;i<=5;i++)
i++;
System.out.println(i);

}
}

Compile Time Error


public class valan {
public static void main(String args[]){
int i,j,k=0;
for(i=1,j=5;i!=j;i++,j--)
k++;
System.out.println(k);

}
}
2
public class valan {
public static void main(String args[]){
int k;
k=k+1;
System.out.println(k);

}
}

Compile Time Error


public class valan {
public static void main(String args[]){
int a=0;
System.out.print(a+++a);
System.out.print(++a+a);
}
}

14
public class valan {
public static void main(String args[]){
System.out.println(args[2]);
}
}

Runtime Error
java valan one two (ArrayIndexOutOfBound
sException)
public class valan {
public static void main(String args[]){
int a=1;
switch(a){
case 1:
case 2:
for(int j=1;j<=5;j++)
break;
case 3:
System.out.println("Hai");
break;
default:
System.out.println("Hello"); Hai
break;
} } }
public class valan {
public static void main(String args[]){
int k;
for(int i=1,k=0;i<=5;i++)
break;
System.out.println(k);
}
}

Compile Time Error


public class valan {
public static void main(String args[]){
int k=0;
for(int i=1;i<=5;i++){
if(false);
else
k++;
}
System.out.println(k);
}
} 5
• public class valan {
• public static void main(String args[]){
• int k=0;
• boolean b=false;
• b=++k>5 && ++k<5;
• b=++k>5 || ++k>5;
• System.out.println(k);
• }
• }
3

You might also like