1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| /**
* @(#)calculmoy.java
*
* calculmoy application
*
* @author
* @version 1.00 2017/10/25
*/
import java.util.*;
public class calculmoy {
public static void charger(int [] t)
{
int rep=0;
int indice=0;
int fin=0;
while (rep!=-1)
{
rep=Terminal.lireInt();
t[indice]=rep;
indice++;
fin=indice--;
}
for (indice=fin;indice<=t.length-1;indice++)
{
t[indice]=-1;
}
}
public static void affichage(int[]t)
{
for(int i=0;i<=19;i++)
{
System.out.println(t[i]);
}
}
public static void moyenne(int[]t)
{
double moyenne=0;
int nb=0;
int indice=0;
while(t[indice]!=-1)
{
moyenne=moyenne+t[indice];
indice++;
nb=nb++;
}
System.out.println( moyenne/nb);
}
public static void main(String[] args) {
int [] tab=new int[20];
charger (tab);
affichage(tab);
moyenne(tab);
System.out.println("Hello World!");
}
} |
Partager