Riddle Program using Arrays, HELP!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sakhawat
    New Member
    • Jan 2014
    • 1

    Riddle Program using Arrays, HELP!

    Code:
    import java.util.Scanner;
    public class riddleGuess
    {
      public static void main (String[] args)
      {
        Scanner myScanner=new Scanner(System.in);
        String[] question= new String[5];
        String[] solution= new String[5];
        String userAnswer= new String();
        int times; times=0;
        
        //initialize arays
        question[0]=("I am weightless, but you can see me. Put me in a bucket, and I'll make it lighter. What am I?");solution[0]=("A hole");
        question[1]=("I have hands that wave at you,/nThough I never say goodbye./nIt's cool for you to be with me,/nEspecially when I say, HI. What am I?  ");solution[1]=("an electric fan");
        question[2]=("Pronounced as one letter,/nAnd written with three,/nTwo letters there are,/nAnd two only in me./nI'm double, I'm single,/nI'm black, blue, and gray,/nI'm read from both ends,/nAnd the same either way./nWhat am I?");solution[2]=("eye");
        question[3]=("You use a knife to slice my head and weep beside me when I am dead. What am I? ");solution[3]=("An onion");
        question[4]=("What is the best way to keep your hat from falling off your head?");solution[4]=("don't put it on your head");
    
        System.out.println("I AM THE SPHINX! PLAY MY GAME OF 5 RIDDLES AND I LET YOU LIVE! You've got three tries for each riddle!");
        System.out.println("\n The first question is: \n" + question[0] + "\n");
       
       
     for (times= 0; times < 3; times++)
    { 
           String userAnwer=myScanner.nextLine();
           System.out.println("You replied "+userAnswer); 
    }
    if (!userAnswer.equals(solution[0]))
    {
           System.out.println("You got it wrong! Try again!");
    }
    else if (userAnswer==solution[0])
    {
           times=4; System.out.println("You got it right!");
    }
    }-
    Last edited by Rabbit; Jan 15 '14, 05:04 AM. Reason: Please use [CODE] and [/CODE] tags when posting code or formatted data.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    You should use code tags when posting code. So what is the problem you are having with the code? Does it compile? Does it show errors when you run it?

    Comment

    Working...