Java program

                First program 
import java.lang.*;
import java.io.*;
class Questions
{
public String [][]qpa; public String[][]qca; 
Questions()throws IOException
{
qpa=new String[10][5];

DataInputStream in=new DataInputStream(System.in);
qpa[0][0]="Which Java statement is used to print output to the screen?";
qpa[0][1]="1.System.Out.Println()";
qpa[0][2]="2.Console.WriteLine()";
qpa[0][3]="3.Print statement()";
qpa[0][4]="4.Output println()";

qpa[1][0]="What is the data type of the variable int x = 10?";
qpa[1][1]="1.Float";
qpa[1][2]="2.Integer"; 
qpa[1][3]="3.String";
qpa[1][4]="4.Double";

qpa[2][0]="Which Java keyword is used to define a class?"; 
qpa[2][1]="1.Class";
qpa[2][2]="2.Public";
qpa[2][3]="3.Void";
qpa[2][4]="4.Static";

qpa[3][0]="Which Java operator is used for bitwise AND operation?"; 
qpa[3][1]="1.&";
qpa[3][2]="2.~";
qpa[3][3]="3.|";
qpa[3][4]="4.^";

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

qpa[5][0]="What is the purpose of the break statement in java ?"; 
qpa[5][1]="1.To exit a loop";
qpa[5][2]="2.To exit a switch statement";
qpa[5][3]="3.To exit a method";
qpa[5][4]="4.To exit the program";

qpa[6][0]="Which Java keyword is used to create a thread?"; 
qpa[6][1]="1.Runnable";
qpa[6][2]="2.Thread";
qpa[6][3]="3.Implements";
qpa[6][4]="4.Extends";

qca=new String[10][2];

qca[0][0]="Which Java statement is used to print output to the screen?";
qca[0][1]="1.System.out.println";

qca[1][0]="What is the data type of the variable int x = 10? ";
qca[1][1]="2.Integer";

qca[2][0]="Which Java keyword is used to define a class?"; 
qca[2][1]="1.Class";

qca[3][0]="Which Java operator is used for bitwise AND operation?"; 
qca[3][1]="1.&";

qca[4][0]="Which of the following Java operators is used for assignment?"; 
qca[4][1]="4.=";

qca[5][0]="What is the purpose of the break statement in java?"; 
qca[5][1]="2.To exit a switch statement";

qca[6][0]="Which Java keyword is used to create a thread?"; 
qca[6][1]="1.Runnable";


}
}
public class qu
{
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];
Questions q=new Questions(); System.out.println("JAVA QUIZ");
System.out.println(" ");

for(i=0;i<7;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<7;i++)
{
if(q.qca[i][1].equals(ans[i]))correct++;
 else
wrong++;
}
 

System.out.println("CORRECT ANSWERS");
for(i=0;i<7;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 Java statement is used to print output to the screen?
1.System.Out.Println()
2.Console.WriteLine()
3.Print statement()
4.Output println()
youranswer:
1
What is the data type of the variable int x = 10?
1.Float
2.Integer
3.String
4.Double
youranswer:
2
Which Java keyword is used to define a class?
1.Class
2.Public
3.Void
4.Static
youranswer:
1
Which Java operator is used for bitwise AND operation?
1.&
2.~
3.|
4.^
youranswer:
1
Which of the following Java operators is used for assignment?
1.+
2.-
3.==
4.=
youranswer:
4
What is the purpose of the break statement in java ?
1.To exit a loop
2.To exit a switch statement
3.To exit a method
4.To exit the program
youranswer:
2
Which Java keyword is used to create a thread?
1.Runnable
2.Thread
3.Implements
4.Extends
youranswer:
1
CORRECT ANSWERS

Which Java statement is used to print output to the screen?
correctanswer:1.System.out.println
youranswer:1.System.Out.Println()

What is the data type of the variable int x = 10?
correctanswer:2.Integer
youranswer:2.Integer

Which Java keyword is used to define a class?
correctanswer:1.Class
youranswer:1.Class

Which Java operator is used for bitwise AND operation?
correctanswer:1.&
youranswer:1.&

Which of the following Java operators is used for assignment?
correctanswer:4.=
youranswer:4.=

What is the purpose of the break statement in java ?
correctanswer:2.To exit a switch statement
youranswer:2.To exit a switch statement

Which Java keyword is used to create a thread?
correctanswer:1.Runnable
youranswer:1.Runnable
Correct=7 wrong=0


Comments

Popular posts from this blog

Profile

Shutdown process