Skip to main content

Java program

                                   Quiz 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]="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

Popular posts from this blog

Profile

Gokila Kiruba View Full Size Contact me Email On Blogger since June 2024 Profile views - 3 Report Abuse My blogs Gokila Kiruba About me Gender Female Industry Student Location Kumbakonam,   TamilNadu,   India Introduction Hi, I’m Gokila Kiruba. I’m currently pursuing my MSc in Computer Science, having completed my BSc in the same field. I have experience in software development, especially with technologies like HTML, Bootstrap, JavaScript, and Java. I’m currently working on projects that involve dynamic web applications and basic database operations. I enjoy learning new things and solving technical challenges. Interests I’m on an exciting journey in the world of computer science. With a passion for technology, I’ve been crafting web applications using tools like HTML, Bootstrap, JavaScript, and Java. I’m always up for a challenge, whether it’s making a website more interactive or diving into database management. I love exploring new ideas and pushing the boundaries of what I...

Student Blog's

STUDENT BLOGS  S.NO NAME REGISTER NO BLOG LINK 1. AKASH .N P23CS366 1.  Product Calculation 2.  Question and Answer 3.  File Operation 4.  Profile 2. AMMU .M P23CS367 1.  Product Calculation 2.  Question and Answer 3.  File Operation 4.  Profile 3. ANBU .M P23CS368 1.  Product Calculation 2.  Question and Answer 3.  File Operation 4.  Profile 4. ANBUMANI .A P23CS369 1.  Product Calculation 2.  Question and Answer 3.  File Operation 4.  Profile 5. ARAVINDHAN .A P23CS370 1.  Product Calculation 2.  Question and Answer 3.  File Operation 4.  Profile 6. BARATH .M P23CS371 1...
 File Operation EXPLANATION : -    File operations involve interacting with files on a computer system, allowing you to create, read, write, and delete files. Common operations include: 1. Open a file – Access a file to read or modify it. 2. Read from a file– Extract data from the file. 3. Write to a file– Add or modify data in the file. 4. Close a file– End the interaction with the file to free up system resources. 5. Delete a file – Remove the file from the system.  These actions help manage data in programs and applicationsapplications PROGRAM:- import java.io.File; import java.io.*; import java.io.FileWriter; import java.io.FileReader; import java.io.BufferedReader; import java.io.IOException; class FSC{      public static void main(String args[])throws IOException { int i; DataInputStream d = new DataInputStream(System.in); String fileName = "msc1.txt"; do { System.out.println("\nwhich type of file operation you want to perform?"); System.out.prin...