私は、異なる種類の温度でユーザーが入力できるようにするコードを作成しています。Javaで自分のコードで最大値と最小値を見つける
ユーザーが入力することができる必要があります:週間人は1週間内の温度を測定しているどのように多くの時間 の
額。 毎週の気温です。
ユーザーが情報を入力したときに、プログラムはで入力されている温度が表示されるはずですが。
プログラムは毎週最低温度を表示する必要があります。 プログラムは毎週最高の気温を表示する必要があります。 プログラムは、すべての週の間、最低温度と最高温度を表示する必要があります。 プログラムには、毎週、およびすべての週の平均気温が表示されます。
これは私が来てどのくらいです:
{
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;
}
}
import java.util。*; //スキャナ、ロケール クラス温度 { \tのpublic static無効メイン(文字列[] args)は具体的に私はちょうど私の中で最低温度を見つける方法を始めるためにいくつかの助けを必要とするコード –
の初めにする必要がありますコード。 –
あなたは 'DoubleSummaryStatistics'を見ることができます。 – Bubletan