-4
import java.util.Scanner;
public class CoinTossGame {
public static void main(String[] args) {
System.out.println("A coin is tossed!");
int Heads=0, Tails=1;
Scanner input = new Scanner (System.in);
System.out.println("Enter your guess."); //Starting message
System.out.println("Press 0 for Heads and 1 for Tails."); //prompts user to enter the input
String Guess = input.nextLine(); //Stored input in variable
int i= (int) (Math.random() * 2); //Store random number
if (Guess==i) {
System.out.println("Nice guess.\nYou are really guenius!!");
}
else {
System.out.println("Opps! wrong guess.");
System.out.println("Try again.");
System.out.println("Thank you.");
}
}
}
我已經downvoted這個問題因爲「我有錯誤」不是有用的問題狀態換貨。請[編輯]您的問題,以包括您收到的錯誤,然後我會考慮收回我的downvote。 –
您正在比較INT與STRING ... – azro
/CoinTossGame.java:19:錯誤:無法比較的類型:字符串和整數 if(Guess == i){ ^ 1 error –