我想访问我使用结构创建的数据,但我似乎无法弄清楚如何。在我的课上,我有3个变量。访问类数据
public class Data
{
private double tempCelc;
private double tempKelv;
private double tempFahr;
}
我也有创建此类
Data(final double tempCelcius)
{
this.tempCelc = tempCelcius;
this.tempFahr = this.celToFar(tempCelcius);
this.tempKelv = this.celToKel(tempCelcius);
}
的7个实例构造函数我不知道怎么我能得到有关访问的具体tempFahr或tempKelv为类的特定实例。这是我的循环使用的构造:
for(int i = 0; i < temperatures.length; i++)
{
System.out.println("Please enter the temperature in Celcius for day " + (i+1));
temperatures[i] = new Data(input.nextDouble());
}
创建的getter/setter的类和访问'tempFahr'一审使用'温度[0] .getTempFahr()'。 – Braj 2014-10-10 19:01:32