我有一个问题。当我运行代码时,输入转换率时出现错误。有人可以在正确的方向帮助我吗?我已经复制了部分代码和错误消息。
代码:
exp
输出+错误:
public static void travelTimeAndBudget() {
Scanner input = new Scanner(System.in);
System.out.print("How many days are you going to spend travelling? ");
int days = input.nextInt();
System.out.print("How much money, in USD, are you planning to spend on your trip? ");
int usd = input.nextInt();
System.out.print("What is the three letter currency symbol for your travel destination? ");
String currency = input.next();
double currencyConvert;
System.out.print("How many " + currency + " are there in 1 USD? ");
currencyConvert = input.nextDouble();
double currencyTotal = (currencyConvert * (double)usd);
double currencyDay = (currencyTotal / (double)days);
System.out.println("If you are travelling for " + days + " days that is the same as" + (days * 24) + " or " + (days * 360) + " minutes");
System.out.println("If you are going to spend $" + usd + " USD that means per day you can spend up to $" + ((double)usd / days) + " USD");
System.out.println("Your total budget in " + currency + " is " + currencyTotal + " " + currency + ", which per day is " + currencyDay + currency);
}
非常感谢您的帮助。
答案 0 :(得分:0)
尝试:
Scanner scanner = new Scanner(System.in).useLocale(Locale.US);
答案 1 :(得分:0)
跟踪错误的一个有用技巧是检查调用堆栈。在错误消息的底部,您有:
在TripPlanner.travelTimeAndBudget(TripPlanner.java:33)中在TripPlanner.main(TripPlanner.java:8)
这告诉您在哪里捕获到异常。 TripPlanner.java的第33行是开始调试代码的地方