Smooxe
Smooxe

Reputation: 11

not a statement illegal start of expression?

Hello I am new to programming and I am trying to create a simple math game were the computer generates a random equation and the player has to solve it before time runs out, and I have come across this little problem were it seems that this block is not a statement as well as an illegal start of expression, could someone explain what is happening here.

for(int i = difficulty; i >= 0; i- -){
    System.out.println(i+"...");
    Thread.sleep(500);
}

Here is the complete code.

import javax.swing.*;

public class CruncherExtreme 
{
    public static void main (String[] args) throws Exception
    {
       int difficulty;

    difficulty = Integer.parseInt(JOptionPane.showInputDialog("How god are your?\n"+"1 = evil genius...\n"+"10 = evil, but not a genius"));
    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);
}

}

Upvotes: 1

Views: 540

Answers (1)

Suresh Atta
Suresh Atta

Reputation: 122008

for(int i = difficulty; i >= 0; i- -){

Should be

for(int i = difficulty; i >= 0; i--){

That post increment symbol (--) have a space in between which is illegal to compiler.

Upvotes: 3

Related Questions