Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2009
    Posts
    26
    Rep Power
    0

    Default for statement help

    I'm having some problems with my code....

    These are the errors
    line 61 -----> illegal statement/not a statement
    line 78 while expected
    line 79 reached en of file while parsing
    4 errors in total

    Java Code:
    import javax.swing.*;
    
    //make a class (container)
    public class EG04
    {
        public static void main (String[] args) throws Exception
        {
            int difficulty;
            difficulty = Integer.parseInt(JOptionPane.showInputDialog
                    ("Your level in math(1-10)?"));
            boolean cont = false;
    
            do
            {
                //reset cont to false
                cont = false;
    
                //random numbers for the equation
                double num1 = (int) (Math.round(Math.random()*10));
    
                double num2;
             do
             {
               num2 = (int) (Math.round(Math.random()*10));
             }
            
             while(num2==0);
             {
                int sign = (int) Math.round(Math.random()*4);
                double answer;
    
                System.out.println("\n\n****");
                if (sign==0)
                {
                    System.out.println(num1+" + "+num2);
                    answer = num1+num2;
                } else if(sign ==1)
                {
                    System.out.println(num1+ " - "+num2);
                    answer = num1-num2;
    
                }else if(sign ==2)
                {
                    System.out.println(num1+ " * "+num2);
                    answer = num1*num2;
    
                }else if (sign==3)
                {
                    System.outprintln(num1+ " / "+num2);
                    answer = num1/num2;
    
                }else
                {
                    System.out.println(num1+ " % "+num2);
                    answer = num1%num2;
    
                }
    
                System.out.println("****\n");
    
                for (int i = difficulty; i >= 0; i- -)
                {
                    System.out.println(i+ "...");
                    Thread.sleep(500);
    
                }
                System.out.println("ANSWER: "+answer);
                String again;
                again = JOptionPane.showInputDialog
                        ("Would you like to play again?");
                if (again.equals("yes"))
                   cont = true;
    
             }
            while(cont);
    
    
        }
    }

    Also a questionf or the while statement at end of code
    How does this code "cont" in the condition make it continue.
    it does equal true, does that trigger something?

    If my questions are to ambiguous I'll reiterate....

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Here you are missing dot after the word out

    Java Code:
    System.outprintln(num1 + " / " + num2);
    It should be as follows.

    Java Code:
    System.out.println(num1 + " / " + num2);

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    In your for loop, you cannot use space characters in condition/increment statements. Following is incorrect, look at the bold text.

    Java Code:
    for (int i = difficulty; i >= 0; [B]i- -[/B])
    You must correct it as follows.

    Java Code:
    for (int i = difficulty; i >= 0; i--)

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    In your for loop, you cannot use space characters in condition/increment statements. Following is incorrect, look at the bold text.

    Java Code:
    for (int i = difficulty; i >= 0; [B]i- -[/B])
    You must correct it as follows.

    Java Code:
    for (int i = difficulty; i >= 0; i--)

  5. #5
    Join Date
    Nov 2009
    Posts
    26
    Rep Power
    0

    Default

    thanks a lot. you've helped me out a great deal.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. The if Statement, need some help!
    By Keno777 in forum New To Java
    Replies: 6
    Last Post: 10-24-2009, 12:53 AM
  2. if statement help please!!
    By soc86 in forum New To Java
    Replies: 5
    Last Post: 12-02-2008, 02:56 PM
  3. If statement, please help??
    By soc86 in forum New To Java
    Replies: 5
    Last Post: 11-23-2008, 02:58 PM
  4. Help with if statement
    By carl in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 07:53 AM
  5. Statement or Prepared Statement ?
    By paty in forum JDBC
    Replies: 3
    Last Post: 08-01-2007, 04:45 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
  •