/** * 632.1 - Exercice 2, Série P02 * * Calculs avec un tableau

/**
*632.1ŞExercice2,SérieP02
*
*Calculsavecuntableau
*
*@authorPeterDAEHNE,HEGŞGenève
*@version1.0
*/
publicclassEx2{
privatestaticfinalintLIMITE=10;/*Déclarationd'uneconstante*/
privatestaticvoidremplir(int[]t){
for(intk=0;k<t.length;k=k+1){
t[k]=(int)Math.round(Math.random()*100);
}
}//remplir
privatestaticvoidafficher(int[]t){
for(intk=0;k<t.length;k=k+1){
System.out.print(t[k]+"");
}
System.out.println();
}//afficher
privatestaticdoublemoyenne(int[]t){
intsomme=0;
for(intk=0;k<t.length;k=k+1){
somme=somme+t[k];
}
return(double)somme/t.length;
}//moyenne
privatestaticintplusGrand(int[]t){
intpG=t[0];
for(intk=1;k<t.length;k=k+1){
if(t[k]>pG){pG=t[k];}
}
returnpG;
}//plusGrand
publicstaticvoidmain(String[]args){
int[]tab=newint[LIMITE];/*Créerletableaude10entiers*/
remplir(tab);
afficher(tab);
System.out.println("Lamoyenne:"+moyenne(tab));
System.out.println("Leplusgrand:"+plusGrand(tab));
}//main
}//Ex2
/**
*632.1ŞExercice2,SérieP02
*
*CalculsavecuneArrayListŞceprogrammeaexactementlemêmeeffetqueEx2.
*
*@authorPeterDAEHNE,HEGŞGenève
*@version1.0
*/
publicclassEx2ArrayList{
privatestaticfinalintLIMITE=10;/*Déclarationd'uneconstante*/
privatestaticvoidremplir(java.util.ArrayListaL){
for(intk=0;k<LIMITE;k=k+1){
intnb=(int)Math.round(Math.random()*100);
Integerobj=newInteger(nb);
aL.add(obj);
}
}//remplir
privatestaticvoidafficher(java.util.ArrayListaL){
for(intk=0;k<aL.size();k=k+1){
Integernb=(Integer)aL.get(k);
System.out.print(nb+"");
}
System.out.println();
}//afficher
privatestaticdoublemoyenne(java.util.ArrayListaL){
intsomme=0;
for(intk=0;k<aL.size();k=k+1){
Integernb=(Integer)aL.get(k);
somme=somme+nb.intValue();
}
return(double)somme/aL.size();
}//moyenne
privatestaticintplusGrand(java.util.ArrayListaL){
IntegerpG=(Integer)aL.get(0);
for(intk=1;k<aL.size();k=k+1){
Integernb=(Integer)aL.get(k);
if(nb.intValue()>pG.intValue()){pG=nb;}
}
returnpG.intValue();
}//plusGrand
publicstaticvoidmain(String[]args){
java.util.ArrayListaL=newjava.util.ArrayList();/*Créerl'instancedeArrayList*/
remplir(aL);
afficher(aL);
System.out.println("Lamoyenne:"+moyenne(aL));
System.out.println("Leplusgrand:"+plusGrand(aL));
}//main
}//Ex2ArrayList
1 / 1 100%

/** * 632.1 - Exercice 2, Série P02 * * Calculs avec un tableau

La catégorie de ce document est-elle correcte?
Merci pour votre participation!

Faire une suggestion

Avez-vous trouvé des erreurs dans linterface ou les textes ? Ou savez-vous comment améliorer linterface utilisateur de StudyLib ? Nhésitez pas à envoyer vos suggestions. Cest très important pour nous !