Как получить все значения массива в другом методе и распечатать их?
Как вывести на экран в методе Main значения массива patientsTemperature, в формате "Температуры пациентов: 36.7 38.95 34.7 32.41"?
public class Main {
public static void main(String[] args) {
float[] temperatureData = Hospital.generatePatientsTemperatures(10);
}
}
public class Hospital {
public static float[] generatePatientsTemperatures(int patientsCount) {
float[] patientsTemperature = new float[patientsCount];
for (int i = 0; i < patientsCount; i++) {
patientsTemperature[i] = Math.round(((float) (Math.random() * 8) + 32) * 100) / (float) 100.0;
//System.out.println(patientsTemperature[i]);
}
return patientsTemperature;
}
}
Ответы (1 шт):
Автор решения: CatException
→ Ссылка
Попробуйте так
public class Main {
public static void main(String[] args) {
Hospital obj_Hospital = new Hospital();
obj_Hospital.generatePatientsTemperatures()
float[] temperatureData = obj_Hospital.generatePatientsTemperatures(10);
}
}
public class Hospital {
public static float[] generatePatientsTemperatures(int patientsCount) {
float[] patientsTemperature = new float[patientsCount];
for (int i = 0; i < patientsCount; i++) {
patientsTemperature[i] = Math.round(((float) (Math.random() * 8) + 32) * 100) / (float) 100.0;
System.out.print(patientsTemperature[i]);
}
return patientsTemperature;
}
}