不是声明非法开始表达?

时间:2015-09-16 08:19:54

标签: java swing compiler-errors

您好我是编程的新手,我正在尝试创建一个简单的数学游戏,计算机生成一个随机方程式,玩家必须在时间用完之前解决它,我遇到了这个小问题,似乎是这个块不是一个声明,也不是一个非法的表达开始,有人可以解释这里发生的事情。

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

这是完整的代码。

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);
}

}

1 个答案:

答案 0 :(得分:3)

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

应该是

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

该后增量符号(--)之间有一个空格,对编译器来说是非法的。