【发布时间】:2015-09-30 02:07:00
【问题描述】:
我的代码出现此错误。
这是我的代码:
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();
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);
}
}
这就是结果。一个错误: 输入模型:线程“main”中的异常 java.lang.NullPointerException 在 car.main(car.java:10)
【问题讨论】:
标签: java exception nullpointerexception main