Commit e26f3430 by Patryk Czarnik

przykład średnia ocen

parent 60b0d7ca
package p07_tablice;
public class SredniaOcen {
public static void main(String[] args) {
int[] oceny = {5, 5, 3, 2, 6, 5};
// za pomocą pętli oblicz średnią tych ocen
int suma = 0;
for(int i = 0; i < oceny.length; i++) {
suma += oceny[i]; // lub suma = suma + oceny[i];
}
double srednia = (double)suma / oceny.length;
System.out.println("Średnia ocen: " + srednia);
}
}
package p07_tablice;
public class SredniaOcen_ForEach {
public static void main(String[] args) {
int[] oceny = {5, 5, 3, 2, 6, 5};
int suma = 0;
for(int ocena : oceny) {
suma += ocena;
}
double srednia = (double)suma / oceny.length;
System.out.println("Średnia ocen: " + srednia);
}
}
package p07_tablice;
public class SredniaOcen_Tlumaczenie {
public static void main(String[] args) {
int[] oceny = {5, 5, 3, 2, 6, 5};
int suma = 0;
suma += oceny[0];
suma += oceny[1];
suma += oceny[2];
suma += oceny[3];
suma += oceny[4];
suma += oceny[5];
double srednia = (double)suma / oceny.length;
System.out.println("Średnia ocen: " + srednia);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment