我對Java非常陌生,試圖從這本書中學習一門課程,並且我堅持製作一個程序。如果是錯誤,並且它不能找到標記爲guessdigit1的符號,請不要告訴我。否則,如果在程序中出現錯誤,不知道哪裏出了什麼問題?
當我將鼠標懸停在符號旁邊的錯誤對話框上時,它總是說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");
}
}
我不知道我怎麼錯過了...我想肯定的IntelliJ告訴我,有那裏不是分號。 +1。 – Makoto
使用大括號是避免這種錯誤 – 2014-01-23 05:55:59
@RC的好方法。肯定。我加了一張關於那個 – Baby