当我尝试运行它时,它给了我一个错误说
Exception in thread "main" java.lang.NullPointerException
at lsamelson_lab5.LSamelson_Lab5.main(LSamelson_Lab5.java:21)
Java Result: 1
第 21 行是要求第一个用户输入的行。
我正在运行 Ubuntu,这是因为我没有正确导入控制台,还是我的 java 文件有问题?
package lsamelson_lab5;
import java.io.Console;
/**
*
* @author binka
*/
public class LSamelson_Lab5 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here\
Console console = System.console();
String input = console.readLine("Please enter your first number:");
int newinput = Integer.parseInt(input);
String input2 = console.readLine("Please enter your second number: ");
int newinput2 = Integer.parseInt(input2);
int sum = newinput + newinput2;
int diff = newinput - newinput2;
int mult = newinput * newinput2;
float div = newinput / newinput2;
System.out.print(sum);
System.out.print(diff);
System.out.print(mult);
System.out.print(div);
}
}