Input/Output Höchste Temperaturschwankung zwischen 2 Tagen

XqlusiveGG

Neues Mitglied
Hallo, wir sollen für die Schule als Hausaufgabe aus Wetterdaten die höchste Temperaturschwankung zwischen 2 Tagen herausfinden. Mein Problem ist, dass bei der Ausgabe in der Konsole nur 14 mal "0.00" kommt.

public class Schwankung {

public static void main(String[] args) {


double[] temperatur = new double[15];
double[] schwankung = new double[15];

temperatur[0] = 19.0;
temperatur[1] = 17.2;
temperatur[2] = 15.2;
temperatur[3] = 14.1;
temperatur[4] = 15.2;
temperatur[5] = 14.7;
temperatur[6] = 12.5;
temperatur[7] = 15.7;
temperatur[8] = 12.8;
temperatur[9] = 15.1;
temperatur[10] = 15.4;
temperatur[11] = 14.8;
temperatur[12] = 18.6;
temperatur[13] = 18.5;
temperatur[14] = 23.3;

for (int x = 0; x < schwankung.length -1; x++)
{
for( int y = 0; y < temperatur.length -1 ; y++)
{
for (int a = 1; a < temperatur.length -1 ; a++)
{
schwankung[x] = temperatur[y] - temperatur[a];

}
}

}

for (int x = 0; x < 14; x++)
{
System.out.println(schwankung[x]);
}


}


}
 
Du musst nur eine For-Schleife verwenden:
Java:
public class Schwankung {

    public static void main(String[] args) {

        double[] temperatur = new double[15];
        double[] schwankung = new double[15];

        temperatur[0] = 19.0;
        temperatur[1] = 17.2;
        temperatur[2] = 15.2;
        temperatur[3] = 14.1;
        temperatur[4] = 15.2;
        temperatur[5] = 14.7;
        temperatur[6] = 12.5;
        temperatur[7] = 15.7;
        temperatur[8] = 12.8;
        temperatur[9] = 15.1;
        temperatur[10] = 15.4;
        temperatur[11] = 14.8;
        temperatur[12] = 18.6;
        temperatur[13] = 18.5;
        temperatur[14] = 23.3;

        // for (int x = 0; x < schwankung.length - 1; x++) {
        // for (int y = 0; y < temperatur.length - 1; y++) {
        for (int a = 1; a < temperatur.length; a++) {
            schwankung[a - 1] = temperatur[a] - temperatur[a - 1];

        }
        // }

        // }

        for (int x = 0; x < 14; x++) {
            System.out.println(schwankung[x]);
        }

    }

}

Ausgabe:
Code:
-1.8000000000000007
-2.0
-1.0999999999999996
1.0999999999999996
-0.5
-2.1999999999999993
3.1999999999999993
-2.8999999999999986
2.299999999999999
0.3000000000000007
-0.5999999999999996
3.8000000000000007
-0.10000000000000142
4.800000000000001
 

Zurück
Oben