Results 1 to 5 of 5
  1. #1
    jumpman8947 is offline Member
    Join Date
    Feb 2013
    Posts
    38
    Rep Power
    0

    Default java array input 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
    Java 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
    XNOViiCE's Avatar
    XNOViiCE is offline Member
    Join Date
    Sep 2013
    Posts
    24
    Rep Power
    0

    Default Re: java array input quiz

    You messed up your answer array a tad bit. If you look at it again the answers aren't lined up with your questions. Also not to insult your intelligence but I have to make sure since this is the new to java area. You know that arrays start at 0. Right?

    Edit: Almost forgot to say this too! You are forgetting to pair your braces up.
    Last edited by XNOViiCE; 09-27-2013 at 08:45 AM.

  3. #3
    jumpman8947 is offline Member
    Join Date
    Feb 2013
    Posts
    38
    Rep Power
    0

    Default Re: java array input quiz

    well forgive me for being human i made a careless mistake everyone does it from time to time.

    Edit: And i didn't paste all of my code that's why i was missing braces.

  4. #4
    XNOViiCE's Avatar
    XNOViiCE is offline Member
    Join Date
    Sep 2013
    Posts
    24
    Rep Power
    0

    Default Re: java array input quiz

    I know, I was just trying to help. Not trying to attack you or anything!

  5. #5
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,988
    Rep Power
    5

    Default Re: java array input quiz

    Quote Originally Posted by jumpman8947 View Post
    well forgive me for being human i made a careless mistake everyone does it from time to time.
    Word of advice: tech forums are all business (except for the obvious to spot jokes). Don't start reading things that aren't there, assume that everything is well-meant until you have proof in the form of actual language that it isn't so.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. HELP - Java quiz application won't run
    By MD1993 in forum New To Java
    Replies: 4
    Last Post: 04-10-2012, 03:13 PM
  2. Please help with java quiz (should be easy to help)
    By karoloydi in forum New To Java
    Replies: 1
    Last Post: 11-29-2011, 02:59 AM
  3. JAVA Quiz
    By sara1988 in forum New To Java
    Replies: 4
    Last Post: 09-14-2011, 05:20 AM
  4. Swing java quiz
    By htuy in forum New To Java
    Replies: 7
    Last Post: 07-08-2011, 06:02 AM
  5. New to java, need a little help with array input
    By black06vfr in forum New To Java
    Replies: 11
    Last Post: 04-29-2009, 05:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •