Java program
PROGRAM :
import java.lang.*;
import java.io.*;
class Questions
{
public String [][]qpa; public String[][]qca;
Questions()throws IOException
{
qpa=new String[10][5];
/*questions and objectives */
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";
qca=new String[10][2];
/*questions and correct answers*/
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";
}
}
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<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];
}
/*calculatecorrectanswers*/
for(i=0;i<8;i++)
{
if(q.qca[i][1].equals(ans[i]))correct++;
else
wrong++;
}
/*printingthecorrectanswersanduserselectedanswers*/
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);
}
}
OUTPUT :
How do you reverse a string in Java?
1.Using StringBuilder
2.Using StringBuffer
3.Using char array
4.Using recursion
youranswer:
1
How do you swap two numbers without using a third variable in Java?
1.Using Arithmetic Operators
2.Using Bitwise XOR Operator
3.Using Multiplication and Division
4.Using Addition and Subtraction
youranswer:
2
Which of the following option leads to the portability and security of Java?
1.Bytecode is executed by JVM
2.The applet makes the Java code secure and portable
3.Use of exception handling
4.Dynamic binding between objects
youranswer:
1
Which of the following is not a Java features?
1.Dynamic
2.Architecture Neutral
3.Use of pointers
4.Object-oriented
youranswer:
3
The ! article referred to as a?
1.Unicode escape sequence
2.Octal escape
3.Hexadecimal
4.Line feed
youranswer:
1
_____ is used to find and fix bugs in the Java programs?
1.JVM
2.JRE
3.JDK
4.JDB
youranswer:
4
Which of the following creates a List of 3 visible items and multiple selections abled?
1.new List(false, 3)
2.new List(3, true)
3.new List(true, 3)
4.new List(3, false)
youranswer:
2
What is the return type of the hashCode() method in the Object class?
1.Object
2.int
3.long
4.void
youranswer:
2
CORRECT ANSWERS
How do you reverse a string in Java?
correctanswer:1.Using StringBuilder
youranswer:1.Using StringBuilder
How do you swap two numbers without using a third variable in Java?
correctanswer:2.Using Bitwise XOR Operator
youranswer:2.Using Bitwise XOR Operator
Which of the following option leads to the portability and security of Java?
correctanswer:1.Bytecode is executed by JVM
youranswer:1.Bytecode is executed by JVM
Which of the following is not a Java features?
correctanswer:3.Use of pointers
youranswer:3.Use of pointers
The ! article referred to as a?
correctanswer:1.Unicode escape sequence
youranswer:1.Unicode escape sequence
_____ is used to find and fix bugs in the Java programs?
correctanswer:4.JDB
youranswer:4.JDB
Which of the following creates a List of 3 visible items and multiple selections abled?
correctanswer:2.new List(3, true)
youranswer:2.new List(3, true)
What is the return type of the hashCode() method in the Object class?
correctanswer:2.int
youranswer:2.int
Correct=8 wrong=0
Comments
Post a Comment