QUIZ
JAVA QUIZ PROGRAM
A simple Java quiz program that you can use as a starting point.
This program will present a series of questions to the user, collect their answers, and then provide a score at the end.
JAVA 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 insert COMMENTS in R code ?";
qpa[0][1]="1.#This is a comment.";
qpa[0][2]="2.//This is a comment.";
qpa[0][3]="3./*This is a comment.";
qpa[0][4]="4.'This is a comment'.";
qpa[1][0]="Which statement is used to stop a loop?";
qpa[1][1]="1.break";
qpa[1][2]="2.exit";
qpa[1][3]="3.return";
qpa[1][4]="4.stop";
qpa[2][0]="How do you start writting an if statement in R?";
qpa[2][1]="1.if x>y then:";
qpa[2][2]="2.if (x>y) ";
qpa[2][3]="3.if x>y:";
qpa[2][4]="4.if x>y";
qpa[3][0]="Which operator is used to add together two values?";
qpa[3][1]="1.The + sign";
qpa[3][2]="2.The * sign";
qpa[3][3]="3.The & sing";
qpa[3][4]="4.The / sign";
qpa[4][0]="How do you create a function in R?";
qpa[4][1]="1.my_function <- function";
qpa[4][2]="2.my_function";
qpa[4][3]="3.my_function <- function()";
qpa[4][4]="4.my_function <- function[]";
qpa[5][0]="Which function can be used to create a data frame?";
qpa[5][1]="1.dframe()";
qpa[5][2]="2.df()";
qpa[5][3]="3.dataframe()";
qpa[5][4]="4.data.frame()";
qpa[6][0]="How do you create a variabe named x with the numeric value 5?";
qpa[6][1]="1.x=5";
qpa[6][2]="2.int x=5";
qpa[6][3]="3.x<-5";
qpa[6][4]="4.x=5;";
qpa[7][0]="Which function is often used to concatenate elements?";
qpa[7][1]="1.join()";
qpa[7][2]="2.concat()";
qpa[7][3]="3.paste()";
qpa[7][4]="4.merge()";
qpa[8][0]="Which operator can be used to campare two values?";
qpa[8][1]="1.<>";
qpa[8][2]="2.=";
qpa[8][3]="3.><";
qpa[8][4]="4.==";
qpa[9][0]="Which function is used to add additional columns in a matrix?";
qpa[9][1]="1.append_item()";
qpa[9][2]="2.cbind()";
qpa[9][3]="3.join()";
qpa[9][4]="4.add()";
qca=new String[10][2];
//questionsandcorrectanswers//
qca[0][0]="How do you insert COMMENTS in R code ?";
qca[0][1]="1.zzzzzzz#This is a comment.";
qca[1][0]="Which statement is used to stop a loop?";
qca[1][1]="1.break";
qca[2][0]="How do you start writting an if statement in R?";
qca[2][1]="2.if (x>y) ";
qca[3][0]="Which operator is used to add together two values?";
qca[3][1]="1.The + sign";
qca[4][0]="How do you create a function in R?";
qca[4][1]="3.my_function <- function()";
qca[5][0]="Which function can be used to create a data frame?";
qca[5][1]="4.data.frame()";
qca[6][0]="How do you create a variabe named x with the numeric value 5?";
qca[6][1]="3.x<-5";
qca[7][0]="Which function is often used to concatenate elements?";
qca[7][1]="3.paste()";
qca[8][0]="Which operator can be used to campare two values?";
qca[8][1]="4.==";
qca[9][0]="Which function is used to add additional columns in a matrix?";
qca[9][1]="2.cbind()";
}
}
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("PROGRAMMING 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 :-
PROGRAMMING QUIZ
How do you insert COMMENTS in R code ?
1.#This is a comment.
2.//This is a comment.
3./*This is a comment.
4.'This is a comment'.
youranswer:
1
Which statement is used to stop a loop?
1.break
2.exit
3.return
4.stop
youranswer:
1
How do you start writting an if statement in R?
1.if x>y then:
2.if (x>y)
3.if x>y:
4.if x>y
youranswer:
2
Which operator is used to add together two values?
1.The + sign
2.The * sign
3.The & sing
4.The / sign
youranswer:
1
How do you create a function in R?
1.my_function <- function
2.my_function
3.my_function <- function()
4.my_function <- function[]
youranswer:
3
Which function can be used to create a data frame?
1.dframe()
2.df()
3.dataframe()
4.data.frame()
youranswer:
4
How do you create a variabe named x with the numeric value 5?
1.x=5
2.int x=5
3.x<-5
4.x=5;
youranswer:
3
Which function is often used to concatenate elements?
1.join()
2.concat()
3.paste()
4.merge()
youranswer:
3
Which operator can be used to campare two values?
1.<>
2.=
3.><
4.==
youranswer:
4
Which function is used to add additional columns in a matrix?
1.append_item()
2.cbind()
3.join()
4.add()
youranswer:
2
CORRECT ANSWERS
How do you insert COMMENTS in R code ?
correctanswer:1.zzzzzzz#This is a comment.
youranswer:1.#This is a comment.
Which statement is used to stop a loop?
correctanswer:1.break
youranswer:1.break
How do you start writting an if statement in R?
correctanswer:2.if (x>y)
youranswer:2.if (x>y)
Which operator is used to add together two values?
correctanswer:1.The + sign
youranswer:1.The + sign
How do you create a function in R?
correctanswer:3.my_function <- function()
youranswer:3.my_function <- function()
Which function can be used to create a data frame?
correctanswer:4.data.frame()
youranswer:4.data.frame()
How do you create a variabe named x with the numeric value 5?
correctanswer:3.x<-5
youranswer:3.x<-5
Which function is often used to concatenate elements?
correctanswer:3.paste()
youranswer:3.paste()
Which operator can be used to campare two values?
correctanswer:4.==
youranswer:4.==
Which function is used to add additional columns in a matrix?
correctanswer:2.cbind()
youranswer:2.cbind()
Correct=9 wrong=1
Comments
Post a Comment