您已经定义了Scanner对象。 使用Scanner对象的实例并设置模型的值。 您可以尝试使用v.next()代替System.console()
import java.util.*;
public class car {
public static void main(String[] args) throws java.io.IOException {
Scanner v = new Scanner(System.in);
String model = new String();
double cost = 0;
System.out.print("Enter model: ");
//model = System.console().readLine();
model = v.next();
if (model == "GL") {
cost = 420000;
}
if (model == "XL") {
cost = 3398000;
}
System.out.print("Car phone: ");
char phone = (char) System.in.read();
if (phone == 'W') {
cost = cost + 40000;
}
System.out.print("Full or installment: ");
char paid = (char) System.in.read();
if (paid == 'F') {
cost = cost - 0.15 * cost;
}
System.out.print("Cost: " + cost);
}
}
输出:
Enter model: GL
Car phone: W
Full or installment: Cost: 40000.0