I am failing to call a method in Java and have been unable to find a solution. Currently getting "cannot resolve symbol findfutureAge". How can I fix?

huangapple go评论70阅读模式
英文:

I am failing to call a method in Java and have been unable to find a solution. Currently getting "cannot resolve symbol findfutureAge". How can I fix?

问题

I can help you with the Chinese translation. Here is the translated code:

我是一名学生对Java还很新我正在尝试编写一个程序根据一个假设的未来年份来计算某人的年龄我正在学习方法以及如何从中调用它们因此这个程序需要使用方法但出于某种原因我无法让它工作我觉得我一定很接近但是错过了一些明显的东西我尝试了几种不同的方法来使其工作但都没有成功目前我得到了一个"无法解析符号findfutureAge"的错误

import java.util.Scanner;
public class Problem1 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入您的姓名:");
        String name = input.nextLine();
        System.out.println("请输入您的年龄:");
        int age = input.nextInt();
        System.out.println("请输入一个未来的年份:");
        int futureYear = input.nextInt();

        System.out.println("您的年龄将会是 " + findFutureAge(age, futureYear));
    }

    public static int findFutureAge(int age, int futureYear) {
        return futureYear - 2021 + age;
    }
}

请注意,我已经将英文翻译成了中文,但代码部分保持不变。希望这对你有所帮助!如果你需要进一步的帮助,请随时告诉我。

英文:

I'm a student and quite new to Java, I am trying to write a program to calculate someone's age given a hypothetical future year. I am learning methods and how to call from them so that is required for this program, but for some reason I can't get this to work. I feel like I must be close but am missing something obvious. I've tried a few different ways to make this work but have had no success. Currently I am getting a "cannot resolve symbol findfutureAge"

import java.util.Scanner;
public class Problem1 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("Please enter your name: ");
        String name = input.nextLine();
        System.out.println("Please enter your age: ");
        int age = input.nextInt();
        System.out.println("Please enter a future year: ");
        int futureYear = input.nextInt();

        System.out.println("Your age would be " + findfutureAge);
    }

    public static int findFutureAge(int age, int futureYear) {
        return futureYear - 2021 + age;
    }
}

答案1

得分: 1

你正在将findfutureAge视为变量,但实际上并没有这个变量。
有一个方法findFutureAge(区分大小写),但你需要添加参数才能实际调用它。

将下一行更改为:

System.out.println("Your age would be " + findFutureAge(age, futureYear));
英文:

You are treating findfutureAge as a variable, but there isn't such variable.
There is a method, findFutureAge (case sensitive), but you'll need to add the parameters in order to actually call it.

Change the next line:

System.out.println("Your age would be " + findfutureAge);

to:

System.out.println("Your age would be " + findFutureAge(age, futureYear));

huangapple
  • 本文由 发表于 2023年6月5日 14:42:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/76404035.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定