Thread: Java quiz

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    23
    Rep Power
    0

    Java quiz


    I'm trying to create a program where there are two array's. An array of questions and an array of answers. Basically i want to show the elements in the question array one by one get the user input, then compare the user input with the same number element in the answer array. For example the first element in question array should be connected with the first element in answer array. Here is the code i have so far, and the problem i'm having is when i check the answer it doesn't return right or wrong. Here is the code thanks
    Code:
    import java.util.*;
    
    public class arrayTest
    {
    	public static void main(String[] args)
    	{
    		String[] question = {"what is bread", "what is milk", "what is sugar", "what is coffee"};
    		String[] anwser = {"a", "c", "a", "b"};
    
    		System.out.println(question[1]);
    				System.out.println("a dairy");
    				System.out.println("b meat");
    				System.out.println("c bread");
    				System.out.println("d sweet");
    
    
    		Scanner scan = new Scanner(System.in);
    
    		String in;
    		in = scan.nextLine();
    
    		if
    			(in.equals(anwser[1]))
    		{
    			System.out.println("Correct");
    		}
  2. #2
  3. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,021
    Rep Power
    1285
    did you use else?

IMN logo majestic logo threadwatch logo seochat tools logo