【发布时间】:2017-03-19 12:20:23
【问题描述】:
我正在创建一个代码,让用户输入不同种类的温度。
用户应该能够输入:
周数 该人在一周内测量了多少次体温。 每周的温度。
当用户输入信息后,程序应显示已输入的温度。
程序应每周显示最低温度。 该程序应每周显示最高温度。 该程序应在所有几周内显示最低和最高温度。 该程序应显示每周和所有星期的平均温度。
这是我已经走了多远:
{
System.out.println ("Temperatures\n");
Scanner in = new Scanner (System.in);
in.useLocale (Locale.US);
//Here is where information is being put in
System.out.print ("amount of weeks: ");
int amountOfWeeks = in.nextInt ();
System.out.print ("measuring temperature per week: ");
int measurementsPerWeek = in.nextInt ();
//array to store the information
double[][] t = new double[amountOfWeeks + 1][measurementsPerWeek + 1];
//mata in temperaturerna
for (int week = 1; week <= amountOfWeeks; week++)
{
System.out.println ("temperatures - week " + week + ":");
for (int measurement = 1; measurement <= measurementsPerWeek; measurement++)
t[week][measurement] = in.nextDouble ();
}
System.out.println ();
//show the temperatures
System.out.println ("temperatures");
for (int week = 1; week <= amountOfWeeks; week++)
{
for (int measurement = 1; measurement <= measurementsPerWeek; measurement++)
System.out.print (t[week][measurement] + " ");
System.out.println ();
}
//lowest, highest, the sum of all temperatures, and average temp per week
double[] minT = new double[amountOfWeeks + 1];
double[] maxT = new double[amountOfWeeks + 1];
double[] sumT = new double[amountOfWeeks + 1];
double[] averageT = new double[amountOfWeeks];
// write the code to find the lowest temperature for the first week
//´Lowest, highest, sum, average for all weeks
double minTemp = minT[1];
double maxTemp = maxT[1];
double sumTemp = sumT[1];
double averageTemp = 0;
}
}
【问题讨论】:
-
导入 java.util.*; //Scanner, Locale class Temperatures { public static void main (String[] args) 应该在代码的开头
-
具体来说,我只需要一些帮助来开始了解如何在我的代码中找到最低温度。
-
你可以看看
DoubleSummaryStatistics。
标签: java arrays sorting max minimum