Quiz Program
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]="How do you reverse a string in Java?";
qpa[0][1]="1.Using StringBuilder";
qpa[0][2]="2.Using StringBuffer";
qpa[0][3]="3.Using char array";
qpa[0][4]="4.Using recursion";
qpa[1][0]="How do you swap two numbers without using a third variable in Java?";
qpa[1][1]="1.Using Arithmetic Operators";
qpa[1][2]="2.Using Bitwise XOR Operator";
qpa[1][3]="3.Using Multiplication and Division";
qpa[1][4]="4.Using Addition and Subtraction";
qpa[2][0]="Which of the following option leads to the portability and security of Java?";
qpa[2][1]="1.Bytecode is executed by JVM";
qpa[2][2]="2.The applet makes the Java code secure and portable";
qpa[2][3]="3.Use of exception handling";
qpa[2][4]="4.Dynamic binding between objects";
qpa[3][0]="Which of the following is not a Java features?";
qpa[3][1]="1.Dynamic";
qpa[3][2]="2.Architecture Neutral";
qpa[3][3]="3.Use of pointers";
qpa[3][4]="4.Object-oriented";
qpa[4][0]="The \u0021 article referred to as a?";
qpa[4][1]="1.Unicode escape sequence";
qpa[4][2]="2.Octal escape";
qpa[4][3]="3.Hexadecimal";
qpa[4][4]="4.Line feed";
qpa[5][0]="_____ is used to find and fix bugs in the Java programs?";
qpa[5][1]="1.JVM";
qpa[5][2]="2.JRE";
qpa[5][3]="3.JDK";
qpa[5][4]="4.JDB";
qpa[6][0]="Which of the following creates a List of 3 visible items and multiple selections abled?";
qpa[6][1]="1.new List(false, 3)";
qpa[6][2]="2.new List(3, true)";
qpa[6][3]="3.new List(true, 3)";
qpa[6][4]="4.new List(3, false)";
qpa[7][0]="What is the return type of the hashCode() method in the Object class?";
qpa[7][1]="1.Object";
qpa[7][2]="2.int";
qpa[7][3]="3.long";
qpa[7][4]="4.void";
qpa[8][0]="Which of the following is a valid long literal?";
qpa[8][1]="1.ABH8097";
qpa[8][2]="2.L990023";
qpa[8][3]="3.904423";
qpa[8][4]="4.0xnf029L";
qpa[9][0]="Which of the following tool is used to generate API documentation in HTML format from doc comments in source code?";
qpa[9][1]="1.javap tool";
qpa[9][2]="2.javaw command";
qpa[9][3]="3.Javadoc tool";
qpa[9][4]="4.javah command";
qca=new String[10][2];
/*questionsandcorrectanswers*/
qca[0][0]="How do you reverse a string in Java?";
qca[0][1]="1.Using StringBuilder";
qca[1][0]="How do you swap two numbers without using a third variable in Java?";
qca[1][1]="2.Using Bitwise XOR Operator";
qca[2][0]="Which of the following option leads to the portability and security of Javad?";
qca[2][1]="1.Bytecode is executed by JVM";
qca[3][0]="Which of the following is not a Java features?";
qca[3][1]="3.Use of pointers";
qca[4][0]="The \u0021 article referred to as a?";
qca[4][1]="1.Unicode escape sequence";
qca[5][0]="_____ is used to find and fix bugs in the Java programs?";
qca[5][1]="4.JDB";
qca[6][0]=" Which of the following creates a List of 3 visible items and multiple selections abled?";
qca[6][1]="2.new List(3, true)";
qca[7][0]="What is the return type of the hashCode() method in the Object class?";
qca[7][1]="2.int";
qca[8][0]="Which of the following is a valid long literal?";
qca[8][1]="2.L990023";
qca[9][0]="Which of the following tool is used to generate API documentation in HTML format from doc comments in source code?";
qca[9][1]="3.Javadoc tool";
}
}
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<10;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<10;i++)
{
if(q.qca[i][1].equals(ans[i]))correct++;
else
wrong++;
}
/*printingthecorrectanswersanduserselectedanswers*/
System.out.println("CORRECT ANSWERS");
for(i=0;i<10;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:
Comments
Post a Comment