我想訪問我使用結構創建的數據,但我似乎無法弄清楚如何。在我的課上,我有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