我有两个问题:我的代码将不会运行,但没有错误
- 为什么我的程序运行?
- 我该如何检查输入是否与某些 有什么不同?
-
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