Java 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]="keyboard?"; 

qpa[0][1]="1.input";

qpa[0][2]="2.java JavaProgram"; 

qpa[0][3]="3.javac JavaProgram.java";

qpa[0][4]="4.No one";

qpa[1][0]="What is the java operators?"; 

qpa[1][1]="1.Arithmetic operators";

qpa[1][2]="2.Relational operators";

qpa[1][3]="3.Logical operators";

qpa[1][4]="4.All of the above";

qpa[2][0]="which is the java keywords?";

qpa[2][1]="1.while";

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

qpa[2][3]="3.for";

qpa[2][4]="4.All of the above";

qpa[3][0]="Which one is the variable name?"; 

qpa[3][1]="1variable";

qpa[3][2]="2.@variable";

qpa[3][3]="3.while";

qpa[3][4]="4.colours";

qca=new String[10][2];

qca[0][0]="keyboard?";

qca[0][1]="1.input";

qca[1][0]="What is the java operators?";

qca[1][1]="4.All of the above";

qca[2][0]="which is the java keywords?"; 

qca[2][1]="4.All of the above";

qca[3][0]="Which one is the variable name?"; 

qca[3][1]="4.colours";

}

}

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=newQuestions();

System.out.println("JAVA QUIZ"); 

System.out.println(" ");

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

}

for(i=0;i<4;i++)

{

if(q.qca[i][1].equals(ans[i]))

correct++;

else

wrong++;

}

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 :

JAVA QUIZ 

keyboard?

1.input

2.java JavaProgram

3.javac JavaProgram.java

4.No one

youranswer:

1

What is the java operators?

1.Arithmetic operators

2.Relational operators

3.Logical operators

4.All of the above

youranswer:

4

which is the java keywords?

1.while

2.if

3.for

4.All of the above

youranswer:

4

Which one is the variable name?

1variable

2.@variable

3.while

4.colours

youranswer:

4

CORRECT ANSWERS


keyboard?

correctanswer:1.input

youranswer:1.input


What is the java operators?

correctanswer:4.All of the above

youranswer:4.All of the above


which is the java keywords?

correctanswer:4.All of the above

youranswer:4.All of the above


Which one is the variable name?

correctanswer:4.colours

youranswer:4.colours

Correct=4 wrong=0





Comments