2nd 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]="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 use ofthe println method?"; qpa[1][1]="1.Itisusedtoprinttextonthescreen.";


qpa[1][2]="2.Itisusedtoprinttextonthescreenwiththelinebreak."; qpa[1][3]="3.Itisusedtoreadtextfromkeyboard.";


qpa[1][4]="4.Itisusedtoread textfromafile.";




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


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


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


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




qpa[3][0]="Whichoneisasingle-linecomment?"; qpa[3][1]="1./...";


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


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


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




qca=new String[10][2];


/*questionsandcorrectanswers*/


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


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




qca[1][0]="Whatistheuseoftheprintlnmethod?";


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




qca[2][0]="Howtoreadacharacterfromthekeyboard?"; 


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




qca[3][0]="Whichoneisasingle-linecomment?"; 


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


}


}


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("corr

ectanswer:"+q.qca[i][1]); System.out.println("youranswer:"+ans[i]);


}


System.out.println("Correct="+correct+"\twrong="+wrong);


}


}






Comments

Popular posts from this blog

II Msc(cs) Student Profile