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 oftenHangOut = integer.parseInt(oftenHangOut);
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.");
}
答案 0 :(得分:1)
我无法在任何地方看到Scanner对象;)但是,我想,你想做类似的事情:
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.");
}
好的技巧是使用try-catch块。你会看到出了什么问题,以及为什么你的appliaction停止了。
答案 1 :(得分:0)
int oftenHangOut = Integer.parseInt(oftenHangOut);
并读取一个int你应该这样做
int oftenHangOut = input.nextInt();