如果没有程序错误,不确定有什么问题?

-1 java

我是java的新手,试图从这本书中学习一门课程并且我坚持制作一个程序.如果没有错误并且无法找到标记为guessdigit1&2的符号,请继续告诉我.

当我将鼠标悬停在符号旁边的错误对话框上时,它一直说guessdigit1和2是他们自己的类.任何的想法?谢谢!

package loterry;

import java.util.Scanner;

public class Loterry {
// This program creates two random numbers, and checks to see if your guess
    // makes the lottery win

    public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    System.out.println("Enter in your guess for loterry, two digits please");
        int lottery = (int)(Math.random()*100 /50);
        int guess = input.nextInt();
        int lotterydigit1= lottery /10;
        int lotterydigit2= lottery %10;

        // Get digits from guess
        int guessdigit1 = guess / 10;
        int guessdigit2 = guess % 10;

        System.out.println("The lottery number is " + lottery);

        if (guess == lottery)
            System.out.println("Exact Match: you win 10,000");
        else if (guessdigit2 == lotterydigit1 && guessdigit1 == lotterydigit2);
            System.out.println("Match all digits: you win 3,000");
        else if (guessdigit1 == lotterydigit1 
                     || guessdigit1 == lotterydigit2
                     || guessdigit2 == lotterydigit2
                     || guessdigit2 == lotterydigit2)
                  System.out.println("match one digit: you win 1,000");
                else
                  System.out.println("sorry no match");




    }
}
Run Code Online (Sandbox Code Playgroud)

Bab*_*aby 11

这是你的问题:

else if (guessdigit2 == lotterydigit1 && guessdigit1 == lotterydigit2);
Run Code Online (Sandbox Code Playgroud)

删除分号(;)

else if (guessdigit2 == lotterydigit1 && guessdigit1 == lotterydigit2)
Run Code Online (Sandbox Code Playgroud)

注意:建议始终if else使用括号编写语句,{ }以避免将来出现任何可能的错误,当然这是在Java代码约定中.(请参阅此答案以澄清括号问题)

else if (guessdigit2 == lotterydigit1 && guessdigit1 == lotterydigit2){
     System.out.println("Match all digits: you win 3,000");
}
Run Code Online (Sandbox Code Playgroud)