我有兩個問題:我的代碼將不會運行,但沒有錯誤
- 爲什麼我的程序運行?
- 我該如何檢查輸入是否與某些 有什麼不同?
-
import java.util.Random;
import java.util.Scanner;
public class HeigherOrLower {
//Creates the scanner.
static Scanner sc = new Scanner(System.in);
static String input = sc.nextLine();
public static void main(String[] args)
{
//Creating the two random numbers.
Random rand = new Random();
int userNumber = rand.nextInt(10) + 1;
int comNumber = rand.nextInt(10) + 1;
System.out.println("Your number is: " + userNumber +" of 10");
System.out.println("Do you think that your number is Heigher(H), Lower(L) or Equal To(E) the computers number");
//Checking if the user is right.
if(userNumber < comNumber && input.equals("L"))
System.out.println("You are right. The computer's number is: " + comNumber);
if(userNumber == comNumber && input.equals("E"))
System.out.println("You are right. The computer's number is: " + comNumber);
if(userNumber > comNumber && input.equals("H"))
System.out.println("You are right. The computer's number is: " + comNumber);
}
}
你如何運行它? –
你認爲'static String input = sc.nextLine();'是做什麼的? –
調試你的代碼,你會發現問題比提問更快。 – Salah