First program

                           FIRST  JAVA PROGRAMMING

import java.lang.*;
import java.io.*;
class Program
{
public String[][]qpa;public String[][]qca; 
Program()throws IOException
{
qpa=new String[10][5];
DataInputStream in=new DataInputStream(System.in);
qpa[0][0]="Which of the following java operators is used for bitwise AND operation?"; 
qpa[0][1]="1.&";
qpa[0][2]="2.&&"; 
qpa[0][3]="3.&";
qpa[0][4]="4.||";

qpa[1][0]="What is the purpose of the finally block in java?"; 
qpa[1][1]="1.To handle exceptions";
qpa[1][2]="2.To execute code regardless of exceptions"; 
qpa[1][3]="3.To declare variables";
qpa[1][4]="4.To call methods";

qpa[2][0]="Which Java collection class is used to store unique elements?"; 
qpa[2][1]="1.ArrayList";
qpa[2][2]="2.HashSet";
qpa[2][3]="3.LinkedList";
qpa[2][4]="4.TreeSet";

qpa[3][0]="Which of the following Java methods is used to convert a string to uppercase?"; 
qpa[3][1]="1.toLowerCase()";
qpa[3][2]="2.toUpperCase()";
qpa[3][3]="3.substring()";
qpa[3][4]="4.indexOf()";

qpa[4][0]="What is the purpose of the break statement in Java?"; 
qpa[4][1]="1.To exit a loop ";
qpa[4][2]="2.To skip a iteration";
qpa[4][3]="3.To executive a block of code";
qpa[4][4]="4.To declare a variable";

qpa[5][0]="Which Java operators is used for assignment?"; 
qpa[5][1]="1.=";
qpa[5][2]="2.+";
qpa[5][3]="3.-";
qpa[5][4]="4.*";

qpa[6][0]="Which Java method is used to print output to the screen?"; 
qpa[6][1]="1.println()";
qpa[6][2]="2.print()";
qpa[6][3]="3.scan()";
qpa[6][4]="4.read()";

qpa[7][0]="What is the purpose of the import statement in Java?";
qpa[7][1]="1.To define a class";
qpa[7][2]="2.To declare a variable";
qpa[7][3]="3.To use a library or package";
qpa[7][4]="4.To call a method";

qpa[8][0]="Which Java data type is used for decimal numbers?"; 
qpa[8][1]="1.float";
qpa[8][2]="2.int";
qpa[8][3]="3.double";
qpa[8][4]="4.string";

qca=new String[10][2];
qca[0][0]="Which of the following Java operators is used for bitwise AND operation?";
qca[0][1]="1.&";

qca[1][0]="What is the purpose of the finally block in Java?";
qca[1][1]="2.To execute code regardless of exceptions";

qca[2][0]="Which Java collection class is used to store unique elements?"; 
qca[2][1]="2.HashSet";

qca[3][0]="Which of the following Java methods is used to convert a string to uppercase?"; 
qca[3][1]="2.toUpperCase()";

qca[4][0]="What is the purpose of the break statement in Java?"; 
qca[4][1]="1.To exit a loop";

qca[5][0]="Which Java operators is used for assignment?"; 
qca[5][1]="1.=";

qca[6][0]=" Which Java method is used to print output to the screen?"; 
qca[6][1]="1.println()";

qca[7][0]="What is the purpose of the import statement in Java?";
qca[7][1]="3.To use a library or package";

qca[8][0]="Which Java data type is used for decimal numbers?"; 
qca[8][1]="3.double";

}
}
public class pro
{
public static void main(String[]args)throws IOException
DataInputStream in=new DataInputStream(System.in);
int x,correct=0,wrong=0,i,j; 
String ans[]=new String[10];
Program q=new Program(); System.out.println("JAVA QUIZ");
System.out.println(" ");

for(i=0;i<9;i++)
{
for(j=0;j<5;j++)
{
System.out.println(q.qpa[i][j]);
}
System.out.println("youranswer:");
 
x=Integer.parseInt(in.readLine());
ans[i]=q.qpa[i][x];
}


for(i=0;i<9;i++)
{
if(q.qca[i][1].equals(ans[i]))correct++;
 else
wrong++;
}
 

System.out.println("CORRECT ANSWERS");
for(i=0;i<9;i++)
{
System.out.println(); System.out.println(q.qpa[i][0]);
System.out.println("correctanswer:"+q.qca[i][1]);
System.out.println("youranswer:"+ans[i]);
}
System.out.println("Correct="+correct+"\twrong="+wrong);
}
}

OUTPUT :-

Which of the following java operators is used for bitwise AND operation?
1.&
2.&&
3.&
4.||
youranswer:
1
What is the purpose of the finally block in java?
1.To handle exceptions
2.To execute code regardless of exceptions
3.To declare variables
4.To call methods
youranswer:
2
Which Java collection class is used to store unique elements?
1.ArrayList
2.HashSet
3.LinkedList
4.TreeSet
youranswer:
2
Which of the following Java methods is used to convert a string to uppercase?
1.toLowerCase()
2.toUpperCase()
3.substring()
4.indexOf()
youranswer:
2
What is the purpose of the break statement in Java?
1.To exit a loop
2.To skip a iteration
3.To executive a block of code
4.To declare a variable
youranswer:
1
Which Java operators is used for assignment?
1.=
2.+
3.-
4.*
youranswer:
1
Which Java method is used to print output to the screen?
1.println()
2.print()
3.scan()
4.read()
youranswer:
1
What is the purpose of the import statement in Java?
1.To define a class
2.To declare a variable
3.To use a library or package
4.To call a method
youranswer:
3
Which Java data type is used for decimal numbers?
1.float
2.int
3.double
4.string
youranswer:
3
CORRECT ANSWERS
Which of the following java operators is used for bitwise AND operation?
correctanswer:1.&
youranswer:1.&
What is the purpose of the finally block in java?
correctanswer:2.To execute code regardless of exceptions
youranswer:2.To execute code regardless of exceptions
Which Java collection class is used to store unique elements?
correctanswer:2.HashSet
youranswer:2.HashSet
Which of the following Java methods is used to convert a string to uppercase?
correctanswer:2.toUpperCase()
youranswer:2.toUpperCase()
What is the purpose of the break statement in Java?
correctanswer:1.To exit a loop
youranswer:1.To exit a loop
Which Java operators is used for assignment?
correctanswer:1.=
youranswer:1.=
Which Java method is used to print output to the screen?
correctanswer:1.println()
youranswer:1.println()
What is the purpose of the import statement in Java?
correctanswer:3.To use a library or package
youranswer:3.To use a library or package
Which Java data type is used for decimal numbers?
correctanswer:3.double
youranswer:3.double
Correct=8 wrong=0
=== Code Execution Successful ===

Popular posts from this blog

PROFILE CREATING

RESUME