英文:
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));
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论