Illegal Start of Expression

Posted by Kraivyne on Stack Overflow See other posts from Stack Overflow or by Kraivyne
Published on 2010-05-01T09:58:33Z Indexed on 2010/05/01 10:07 UTC
Read the original article Hit count: 191

Filed under:
|
|

Hello there, I have just started to learn the very basics of Java programming. Using a book entitled "Programming Video Games for the Evil Genius".

I have had an Illegal Start of Expression error that I can't for the life of me get rid of. I have checked the sample code from the book and mine is identical.

The error is coming from the for(int i = difficulty; i >= 0; i- - ) line.

Thanks for helping a newbie out.

import javax.swing.*;

public class S1P4

   {public static void main(String[] args) throws Exception {

    int difficulty;
    difficulty = Integer.parseInt(JOptionPane.showInputDialog("How good are you?\n"+
            "1 = Great\n"+"10 = Terrible"));

    boolean cont = false;

    do
    {

        cont = false;

        double num1 = (int)(Math.round(Math.random()*10));

        double num2;
        do
        {
            num2 = (int)(Math.round(Math.random()*10));
        }
        while(num2==0.0);

        int sign = (int)(Math.round(Math.random()*3));

        double answer;

        System.out.println("\n\n*****");

        if(sign==0)
        {
            System.out.println(num1+" times "+num2);
            answer = num1*num2;
        }
        else if(sign==1)
        {
            System.out.println(num1+" divided by"+num2);
            answer = num1/num2;
        }
        else if(sign==1)
        {
            System.out.println(num1+" plus "+num2);
            answer = num1+num2;
        }
        else if(sign==1)
        {
            System.out.println(num1+" minus "+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("Play again?");

        if(again.equals("yes"))
            cont = true;
    }

    while(cont);

} }

© Stack Overflow or respective owner

Related posts about java

Related posts about beginner