Java 如何修复预期的错误?

Java 如何修复预期的错误?,java,identifier,Java,Identifier,代码返回预期错误。我不知道为什么会发生这种错误 package com.company; import java.util.Scanner; public class Main { public static void main(String[] args) { intro(); time(); } public static void intro() { System.out.println("Welcome

代码返回预期错误。我不知道为什么会发生这种错误

package com.company;


import java.util.Scanner;


public class Main {

    public static void main(String[] args) {
        intro();
        time();
    }

    public static void intro() {

        System.out.println("Welcome");
        System.out.println("What is your name");
        Scanner input = new Scanner(System.in);

        String name = input.nextLine();
        System.out.println("Nice to meet you," + name + " where are you travelling to?");
        String dest = input.nextLine();
        System.out.println("Great!" + dest + " sounds like a great trip");
    }

    public static void time() {
        Scanner input = new Scanner(System.in);

        int hours, minutes;
        float perd, perdc, change;

        System.out.println("How many days are you going to spend travelling?");

        int days = input.nextInt();

        hours = days * 24;
        minutes = hours * 60;

        System.out.println("How much money in USD are you going to spend?");

        Double money = input.nextDouble();
        perd = (money / days);

        System.out.println("What is the three letter currency symbol of your destination?");

        String curr = input.nextLine();

        System.out.println("How many" + curr + "are there in 1USD?");

        Double ex = input.double();
        change = money * ex;
        perdc = perd * ex;

        System.out.println("If you are travelling for" + days + "that is the same as" + hours + "or" + minutes + "minutes");
        System.out.println("If you are going to spend" + money + "$USD that means per day you can spend upto $" + perd + "USD");
        System.out.println("Your total budget in" + ex + "is" + change + ex + ",which per day is  " + perdc + curr);
    }
}

我很高兴看到peaple学习Java,也很高兴看到peaple帮助年轻人。 当我看到您的代码时,我的第一个建议是获得一个好的IDE,如Eclipse、IntelliJ或Netbeans,它将帮助您快速查看编译错误

我的第二个建议是看一下开发规范,作为一名大三学生,我认为这是您必须学习的第一种方法,以获得全面且可维护的代码

例如,请避免在方法签名和第一个声明之间添加几行空白。 我几乎没碰过你的代码就让它工作了。 我希望你会喜欢Java

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        intro(input);
        time(input);
    }

    public static void intro(Scanner input) {
        System.out.println("Welcome");
        System.out.println("What is your name");

        String name = input.nextLine();
        System.out.println("Nice to meet you, " + name + " where are you travelling to?");
        String dest = input.nextLine();
        System.out.println("Great! " + dest + " sounds like a great trip");
    }

    public static void time(Scanner input) {
        int hours, minutes;
        float perd, perdc, change;

        System.out.println("How many days are you going to spend travelling?");

        int days = input.nextInt();

        hours = days * 24;
        minutes = hours * 60;

        System.out.println("How much money in USD are you going to spend?");

        Float money = input.nextFloat();
        perd = money / days;

        System.out.println("What is the three letter currency symbol of your destination?");

        String curr = input.nextLine();

        System.out.println("How many " + curr + " are there in 1USD?");

        Float ex = input.nextFloat();
        change = money * ex;
        perdc = perd * ex;

        System.out.println("If you are travelling for " + days + " that is the same as " + hours + " or " + minutes + " minutes");
        System.out.println("If you are going to spend " + money + " $USD that means per day you can spend upto $" + perd + " USD");
        System.out.println("Your total budget in " + ex + " is " + change + ex + " ,which per day is  " + perdc + curr);
    }

当询问构建错误时,始终包括完整和完整的错误输出。并在显示的代码中添加注释,其中错误是消息中通常报告的行号。另外,请花一些时间阅读,以及.hours、minutes等需要声明为变量类型。@DeaneKane声明存在。扫描仪的文档既不难找到,也不难阅读,所以我真的很想知道您是如何提出input.double或input.int的。