Java 更新的util.scanner重复方法

Java 更新的util.scanner重复方法,java,string,methods,return,java.util.scanner,Java,String,Methods,Return,Java.util.scanner,我已经修复了原始代码中的错误并正确格式化了它。但是,代码现在正在重复字符串next,然后再继续执行最后一个方法。我想我明白了原因,但当我试图修复它时,程序又失败了。谢谢你抽出时间 import java.util.Scanner; public class LearnScanner { public static void main (String[] args) { first(); next(); third(); }

我已经修复了原始代码中的错误并正确格式化了它。但是,代码现在正在重复字符串next,然后再继续执行最后一个方法。我想我明白了原因,但当我试图修复它时,程序又失败了。谢谢你抽出时间

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");
    }


    }

从我看到的情况来看,接下来的方法从主方法调用一次,然后在第三次调用时再次调用

int days = Integer.valueOf(next());
也许您应该创建一个名为days的实例变量,并在其中存储next的值。然后在第三种方法中使用变量的值。i、 e

import java.util.Scanner;

public class LearnScanner {
    private static int days = 0;

    public static void main (String[] args) {
        first();
        days = Integer.parseInt(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 tempDays = Integer.valueOf(days);
        int hours = days * 24;
        int minutes = hours * 60;
        System.out.println("If your are travelling for " + tempDays + " days that is the same as " + hours + " hours or " + minutes + " minutes");
    }

这是正确的答案应用此更改后,我得到以下错误:java:不兼容类型:java.lang.String无法转换为intI get that。。您应该将字符串转换为整数。我将重构代码now@ErikBrabo我已经为更新添加了conversionTank,但是错误是:java:variable days可能尚未初始化