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로 변환 할 수 없습니다 정수. 지금 코드를 리펙토링합니다. –