Qu.java
import java.lang.*;
import java.io.*;
class Questions{
public String [][]qpa; public String[][]qca;
Questions()throws IOException
{
qpa=new String[10][5];
/*questionsandobjectives*/
DataInputStream in=new DataInputStream(System.in);
qpa[0][0]="what is brain of computer?"; qpa[0][1]="1.cpu";
qpa[0][2]="2.memory"; qpa[0][3]="3.keyboard";qpa[0][4]="mouse";
qpa[1][0]="what is the basis unit of information in computing ?"; qpa[1][1]="1.byte.";
qpa[1][2]="2.bit."; qpa[1][3]="3.kilobyte.";
qpa[1][4]="4.mega byte.";
qpa[2][0]="which part of a computer stores data temporarily?"; qpa[2][1]="1.hard drive";
qpa[2][2]="2.ram";
qpa[2][3]="3.cpu";
qpa[2][4]="4.monitor";
qpa[3][0]="which computer component connects of the internet ?"; qpa[3][1]="1.mouse";
qpa[3][2]="2.keyboard";
qpa[3][3]="3.modem";
qpa[3][4]="speaker";
qca=new String[10][2];
/*questionsandcorrectanswers*/
qca[0][0]="what is the brain of a computer?";
qca[0][1]="1.cpu";
qca[1][0]="what is the basic unit of information in computing?";
qca[1][1]="2.bit.";
qca[2][0]="which part of computer stores data temporarily ?";
qca[2][1]="2.ram";
qca[3][0]="which computet component connects to the internet?";
qca[3][1]="3.modem";
}
}
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(" ");
/*forlooptodisplayquestionandreadtheanswerfromtheuser*/
for(i=0;i<4;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];
}
/*calculatecorrectanswers*/
for(i=0;i<4;i++){
if(q.qca[i][1].equals(ans[i]))correct++;
else
wrong++;
}
/*printingthecorrectanswersanduserselectedanswers*/
System.out.println("CORRECT ANSWERS");
for(i=0;i<4;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);
}
}
Out put
JAVA QUIZ
what is brain of computer?
1.cpu
2.memory
3.keyboard
mouse
youranswer:
1
what is the basis unit of information in computing ?
1.byte.
2.bit.
3.kilobyte.
4.mega byte.
youranswer:
2
which part of a computer stores data temporarily?
1.hard drive
2.ram
3.cpu
4.monitor
youranswer:
2
which computer component connects of the internet ?
1.mouse
2.keyboard
3.modem
speaker
youranswer:
3
CORRECT ANSWERS
what is brain of computer?
correctanswer:1.cpu
youranswer:1.cpu
what is the basis unit of information in computing ?
correctanswer:2.bit.
youranswer:2.bit.
which part of a computer stores data temporarily?
correctanswer:2.ram
youranswer:2.ram
which computer component connects of the internet ?
correctanswer:3.modem
youranswer:3.modem
Correct=4 wrong=0
=== Code Execution Successful ===
Comments
Post a Comment