Java 扫描仪出错
下一行有问题,我不知道如何解决Java 扫描仪出错,java,Java,下一行有问题,我不知道如何解决 System.out.println("Thats cool, I have thought that was a very interesting activity, how many hours a week do you do that."); String oftenHangOut = input.nextLine(); 要读取int,你应该这样做 int oftenHangOut = Integer.parseInt(oftenHangOut);
System.out.println("Thats cool, I have thought that was a very interesting activity, how many hours a week do you do that.");
String oftenHangOut = input.nextLine();
要读取int,你应该这样做
int oftenHangOut = Integer.parseInt(oftenHangOut);
我在任何地方都看不到扫描仪对象;)但是,我认为,你想做这样的事情:
int oftenHangOut = input.nextInt();
或不进行分析:
Scanner sc = new Scanner(System.in);
System.out.println("Thats cool, I have thought that was a very interesting activity, how many hours a week do you do that.");
String oftenHangOut = sc.nextLine();
int parsedInt = Integer.parseInt(oftenHangOut);
if (parsedInt > 10) {
System.out.println("Wow thats a lot you must love to do that.");
} else {
System.out.println("Cool, you must love to do that.");
}
好的技巧是使用试抓拦网。您将看到出现了什么问题,以及应用程序停止的原因 首先,您可以解释它应该做什么,以及它应该做什么。integer不是类名,而是integer
Scanner sc = new Scanner(System.in);
System.out.println("Thats cool, I have thought that was a very interesting activity, how many hours a week do you do that.");
String oftenHangOut = sc.nextLine();
int parsedInt = Integer.parseInt(oftenHangOut);
if (parsedInt > 10) {
System.out.println("Wow thats a lot you must love to do that.");
} else {
System.out.println("Cool, you must love to do that.");
}
Scanner sc = new Scanner(System.in);
System.out.println("Thats cool, I have thought that was a very interesting activity, how many hours a week do you do that.");
int oftenHangOut = sc.nextInt();
if (oftenHangOut > 10) {
System.out.println("Wow thats a lot you must love to do that.");
} else {
System.out.println("Cool, you must love to do that.");
}