/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
public class Main {
public static void main(String[] args) {
double[] notes = {
12.5, 15.0, 18.0, 9.5, 10.0, 11.5, 10.0, 9.0, 7.0, 12.0,
14.0, 13.5, 5.5, 10.0, 15.0, 18.0, 19.0, 12.0, 14.5, 13.0,
20.0, 9.5, 9.5, 10.0, 12.0, 2.0, 11.0, 7.0
};
double min, max, moyenne, ecartType, mediane;
double temp;
int i;
// Calcul du min
min = notes[0];
for (i = 1; i < 28; i++) {
if (notes[i] < min) {
min = notes[i];
}
}
System.out.println("min : " + min);
// Calcul du max
max = notes[0];
for (i = 1; i < 28; i++) {
if (notes[i] > max) {
max = notes[i];
}
}
System.out.println("max : " + max);
// Calcul de la moyenne
moyenne = 0;
for (i = 0; i < 28; i++) {
moyenne += notes[i];
}
moyenne = moyenne / 28;
System.out.println("moyenne : " + moyenne);
// Calcul de l'écart type
ecartType = 0;
for (i = 0; i < 28; i++) {
ecartType += Math.pow(notes[i] - moyenne, 2);
}
ecartType = Math.sqrt(ecartType / (28 - 1));
System.out.println("ecart type : " + ecartType);
// Tri à bulle non optimisé
for (int j = 28 - 1; j > 0; j--) {
for (i = 0; i < j; i++) {
if (notes[i] > notes[i + 1]) {
temp = notes[i];
notes[i] = notes[i + 1];
notes[i + 1] = temp;
}
}
}
for (i = 0; i < 28; i++)
System.out.print(notes[i] + "\t");
System.out.println();
// Calcul de la médiane
mediane = (notes[(28 - 1) / 2] + notes[28 / 2]) / 2;
System.out.println("mediane : " + mediane);
}
}