Quiz program

 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 the size of float and double in java?"; qpa[0][1]="1.32 and 64";


qpa[0][2]="2.32 and 32"; qpa[0][3]="3.64 and 64";


qpa[0][4]="4.64 and 32";

qpa[1][0]="number of primitive data type in java?"; qpa[1][1]="1.6";

qpa[1][2]="2.7"; qpa[1][3]="3.8";qpa[1][4]="4.9";

qpa[2][0]="arrays in java are?"; qpa[2][1]="1.object references";

qpa[2][2]="2.object";

qpa[2][3]="3.primitive data type";

qpa[2][4]="4.none";


qpa[3][0]="when is the object created with new keyword?"; qpa[3][1]="1.at run time";

qpa[3][2]="2.at compile time";

qpa[3][3]="3.depends on the code";

qpa[3][4]="4.none/";


qca=new String[10][2];

//questionsandcorrectanswers//

qca[0][0]="what is the size of float and double In Java?";

qca[0][1]="1.32 and 64";


qca[1][0]="number of primitive data type in java?";

qca[1][3]="3.8";


qca[2][0]="arrays in java are?"; 

qca[2][1]="2.objects";


qca[3][0]="when is the object created with new keyword?"; 

qca[3][1]="1.at run time";

}

}

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);

}

Output:

d:\yuva>javac qu.java

Note: qu.java uses or overrides a deprecated API.

Note: Recompile with -Xlint:deprecation for details.


d:\yuva>java qu

JAVA QUIZ

What is the size of float and double in java?


1.32 and 64

2.32 and 32

3.64 and 646

4.64 and 32

youranswer:

1

Number of primitive data type in java?

1.6

2.7

3.8

4.9

youranswer:

3


arrays in java are?

1.object references

2.object

3.primitive data type

4.none

youranswer:

2

when is the object created with new keyword?

1.at run time

2.at compile time

3.depends on the code

4.none/

youranswer:

1

Correct answer:1

Correct=3 wrong=1


d:\yuva>java qu

}

Comments

Popular posts from this blog

Bio Data

File operation

Product calculation