A Little Quiz
import java.util.Scanner;
public class quiz
{
public static void main( String[] args)
{
Scanner keyboard = new Scanner(System.in);
String ready;
int one;
int two;
int three;
int correct=0;
System.out.println("R U ready 4 a quiz?");
ready = keyboard.next();
System.out.println("Here we go!");
System.out.println("Q1) What's the Capital of Alaska?");
System.out.println("1) Melbourne");
System.out.println("2) Anchorage");
System.out.println("3) The North Pole");
one = keyboard.nextInt();
if ( one == 1 )
{
System.out.println("Sorry, it was #2");
}
else if ( one == 2)
{
System.out.println("Congrats! 1 for 1");
correct=correct +1;
}
else if ( one == 3 )
{
System.out.println("Nope, #2");
}
System.out.println(" Q2) Can you store the value cat in a variable of type int?");
System.out.println("1) yes");
System.out.println("2) no");
two = keyboard.nextInt();
if ( one == 1 )
{
System.out.println("Nope, only numbers can be stored as ints");
}
else if ( one == 2)
{
System.out.println("Yup");
correct=correct +1;
}
else
{
System.out.println("Nope, #2");
}
System.out.println("Q3) What is the result of 9+6/3");
System.out.println("1) 5");
System.out.println("2) 11");
System.out.println("3) 15/30");
three = keyboard.nextInt();
if ( one == 1 )
{
System.out.println("Sorry, it was #2");
}
else if ( one == 2)
{
System.out.println("Congrats!");
correct=correct +1;
}
else if ( one == 3 )
{
System.out.println("Nope, #2");
}
else
{
System.out.println("thats not an option");
}
System.out.println(" Overall, you got " + correct + " out of 3 correct.");
}
}
Picture of the output