0
元のコードでエラーを修正し、正しくフォーマットしました。しかし、コードは最後のメソッドに進む前にString next()を繰り返しています。私は理由を理解したと思ったが、修正しようとしたときにプログラムが再び失敗した。あなたの時間をありがとう!私が見たものから、util.scannerの反復方法が更新されました
import java.util.Scanner;
public class LearnScanner {
public static void main (String[] args) {
first();
next();
third();
}
public static void first() {
Scanner input = new Scanner(System.in);
System.out.println("Welcome to Vacation Planner!!");
System.out.print("What is your name?");
String name = input.nextLine();
System.out.print("Nice to meet you " + name + ", where are you travelling to?");
String destination = input.nextLine();
System.out.println("Great! "+destination +" sounds like a great trip");
}
public static String next() {
Scanner input = new Scanner(System.in);
System.out.print("How many days are you going to spend travelling?");
String days = input.nextLine();
System.out.print("How much money in USD are you planning to spend on your trip?");
String budget = input.nextLine();
System.out.print("What is the three letter currency symbol for your travel destination?");
String currency = input.nextLine();
System.out.print("How many " + currency + " are there in 1 USD?");
String currencyConversion = input.nextLine();
return days;
}
public static void third() {
int days = Integer.valueOf(next());
int hours = days * 24;
int minutes = hours * 60;
System.out.println("If your are travelling for " + days + " days that is the same as " + hours + " hours or " + minutes + " minutes");
}
}
これは、私は次のエラーを取得するこの変更を適用した後、正しい答え – mvreijn
あるjava.lang.Stringでは、私は..あなたがに文字列を変換する必要があることを得る –
をintに変換することはできません整数。私は今コードをリファクタリングします –