我遇到了我的代码输出问题。似乎我缺少我创建的方法中的某些东西...我有指示返回总英寸数。返回后我放置totInches,并得到一个错误,指出totInches不是一个变量。不确定这里缺少什么,因为我只是想创建一个方法。大部分代码都是写入的,我应该创建的唯一部分是第二个convertToInches方法..任何建议?转换高度为英寸(Java)
import java.util.Scanner;
public class FunctionOverloadToInches {
public static double convertToInches(double numFeet) {
return numFeet * 12.0;
}
public static double convertToInches(double numFeet, double numInches) {
return totInches * 12.0;
}
public static void main (String [] args) {
double totInches = 0.0;
totInches = convertToInches(4.0, 6.0);
System.out.println("4.0, 6.0 yields " + totInches);
totInches = convertToInches(5.9);
System.out.println("5.9 yields " + totInches);
return;
}
}
它可能是但是大部分代码在软件中是不可编辑的,我们的类运行它,所以我只允许编辑给我的东西,那就是“public static double convertToInches(double numFeet,double numInches ){ return totInches * 12.0; } “ –
您的'convertToInches'方法中的变量'totInches'未声明,它在您的方法无法访问的主方法中。换句话说,'convertToInches'中的'totInches'没有范围,或者是'null'可能是 –
首先在你的脑海中解决问题。如何计算英寸,给定一个英尺的数字和另外的英寸的数字?以convertToInches(double numFeet)方法为指导。您没有遇到Java或编程问题,而只是概念化手头的任务。 – MarsAtomic