V.Vignesh , P23CS398

 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]="How to run Javaprogram on the command prompt?"; 

qpa[0][1]="1.javac JavaProgram";

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 use of the println method?"; 

qpa[1][1]="1.It is used to print text on the screen.";

qpa[1][2]="2.It is used to print text on the screen with the linebreak."; 

qpa[1][3]="3.It is used to read text from keyboard.";

qpa[1][4]="4.It is used to read text from a file.";


qpa[2][0]="How to read a character from the keyboard?"; 

qpa[2][1]="1.char c=System.read()";

qpa[2][2]="2.charc=System.in.read()";

qpa[2][3]="3.charc=(char)System.read()";

qpa[2][4]="4.char c=(char)System.in.read()";


qpa[3][0]="Which one is a single-linecomment?"; 

qpa[3][1]="1./...";

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

qpa[3][3]="3./*...";

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


qpa[4][0]="Which scanner class method is used to read integer value from the user ?";

qpa[4][1]="1.next()";

qpa[4][2]="2.nextInteger()";

qpa[4][3]="3.nextInt()";

qpa[4][4]="4.readInt()";


qpa[5][0]="Which scanner class method isused to read string value from the user ?";

qpa[5][1]="1.next()";

qpa[5][2]="2.nextString()";

qpa[5][3]="3.nextline()";

qpa[5][4]="4.Both 1 and 3";


qpa[6][0]="Which is the correct syntax to declare scanner class object ?";

qpa[6][1]="1.Scanner objectname= Scanner();";

qpa[6][2]="2.Scanner objectname= new scanner();";

qpa[6][3]="3.Scanner objectname= Scanner(System.in);";

qpa[6][4]="4.Scanner objectname= new Scanner(System.in);";


qpa[7][0]="Which package should be imported to use Scanner class ?";

qpa[7][1]="1.import java.util.System.in;";

qpa[7][2]="2.import java.util.Scanner;";

qpa[7][3]="3.import java.util.System.in;";

qpa[7][4]="4.import java.util.input;";

  

qca=new String[10][2];

qca[0][0]="How to run Javaprogram on the commandprompt?"; 

qca[0][1]="2.java JavaProgram";

qca[1][0]="What is the use of the println method ?";

qca[1][1]="2.It is used to print text on the screen with the linebreak.";

qca[2][0]="How to read a character from the keyboard?"; 

qca[2][1]="4.char c=(char)System.in.read()";

qca[3][0]="Which one is a single-linecomment?"; 

qca[3][1]="2.//...";

qca[4][0]="Which scanner class method is used to read integer value from the user ?";

qca[4][1]="3.nextInt()";

qca[5][0]="Which scanner class method isused to read string value from the user ?";

qca[5][1]="4.Both 1 and 3";

qca[6][0]="Which is the correct syntax to declare scanner class object ?";

qca[6][1]="4.Scanner objectname= new Scanner(System.in);";

qca[7][0]="Which package should be imported to use Scanner class ?";

qca[7][1]="2.import java.util.Scanner;";

}

}

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<8;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<8;i++)

{

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

 else

wrong++;

}

 

System.out.println("CORRECT ANSWERS");

for(i=0;i<8;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);

}

}

                         Image : 1

                     Image : 2

                      Image : 3


                             Image : 4



                     Image : 5



Comments