Still need help for a riddle program!!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ImortalSorrow
    New Member
    • Feb 2008
    • 13

    Still need help for a riddle program!!!

    Please I need urgent help with this program! Everything is working well except a part where i want to repeat the riddle if the answer isnt correct. here's the code..hope someone can help me!


    Code:
    import java.util.Scanner;
     
    class TheRiddle {
            
      
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            String playername;
            String riddleanswer;
            char yesorno;
        
                
        System.out.println("enigma!");
        System.out.print("write your name: ");
        playername = scanner.nextLine();
        System.out.println("");
        System.out.println("hey " + playername + ". blablabla" );
        System.out.print("press 'Enter' when ready");
        scanner.nextLine();
        System.out.println("");
        
      [B]  do {System.out.println("riddle nÂș 1..blablabla");
        riddleanswer = scanner.nextLine()}
        
        while (if (riddleanswer.equals("2") || riddleanswer.equals("two") {     
                System.out.println("nice!");
        } else {
            System.out.println("Upss.."));[/B]        
        
        }
    System.out.print("press 'Enter' to continue");
        scanner.nextLine();
       System.out.println("");
       System.out.println("2nd riddle...blablabla
       riddleanswer = scanner.nextLine();
          
       scanner.nextLine();
       System.out.println("");
     
     
     
        }
                    
            
            }
                
          }
    Same thing fot the second riddle...

    Thanks
  • Laharl
    Recognized Expert Contributor
    • Sep 2007
    • 849

    #2
    Please only create one thread per problem.

    Your do loop needs a while condition, as specified in the link I posted in your other thread to Sun's Java tutorial.

    Comment

    Working...