Problème compilation- Classe Entier
Bonsoir à tous,
je viens de finir mon projet qui porté sur les Entiers...Je pense avoir bien réussi mes classes. Cependant lors de la compilation de ma classe ESSAI, on m'affiche
1
2
3
4
5
6
7
8
9
2
8
3
7
1
1
je retrouve la moitié de ce que je voudrais obtenir(je voudrais obtenir en plus un résultat pour l'addition et un autre pour la multiplication) et je comprend pas pourquoi mes résultats s'affichent ainsi (un par ligne)
De plus je ne sais pas qd je met : i=i+1; dans la méthode Afficher cela soit juste....
Sinon Voici mes 2 classes, S'il vous plait dites moi ou je plante...Merci beaucoup
Code:
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
public class Entier {
final static int Nmax = 20;
int [] tab;
public Entier(int [] tab_0){
tab = new int[Nmax];
for(int i=0; i < Nmax; i++){
tab[i]=0;
}
for(int i=0; i < tab_0.length; i++){
tab[tab.length-1-i] = tab_0[tab_0.length-1-i];
}
}
public void afficher(){
int i=0;
while(tab[i]==0){i=i+1;
}
for(int j=i; j<Nmax; j++){
System.out.println(tab[j]);
}
}
public Entier(int x){
tab = new int[Nmax];
for(int i=0; i<Nmax; i++){
tab[i]=0;
}
int val = x;
for(int i = 9; i>=0; i--){
tab[tab.length-1-i]=val/puissanceDix(i);
val = val-puissanceDix(i)*(val/puissanceDix(i));
}
}
public static int puissanceDix(int a){
int res = 1;
for(int i=0; i<a; i++){
res = res*10;
}
return res;
}
public static Entier additionner(Entier a, Entier b){
int retenue = 0;
Entier res2 = new Entier(0);
for(int i=Nmax-1; i>=0; i--){
res2.tab[i]=((a.tab[i])+(b.tab[i]))/10+retenue;
retenue = ((a.tab[i])+(b.tab[i]))/10;
}
return res2;
}
public boolean inferieur(Entier z){
boolean res4 = false;
for(int i=0; i<Nmax; i++){
if(tab[i]<z.tab[i]){
res4 = true;
break;
}
if(z.tab[i]<tab[i]){
break;
}
}
return res4;
}
public static Entier multiplier(Entier x, Entier y){
Entier res3 = new Entier(0);
for(Entier i = new Entier(0); i.inferieur(y); i=additionner(i,i)){
res3 = additionner(res3, x);
}
return res3;
}
} |
Code:
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
|
public class Essai {
public static void main(String[] args) {
int []tab = {1,2,3,4,5,6,7,8,9};
Entier Reel1 = new Entier(tab);
Reel1.afficher();
System.out.println("");
Entier Reel2 = new Entier(2837);
Reel2.afficher();
System.out.println("");
Entier Reel6 = new Entier(365);
Entier Reel7 = new Entier(711);
Entier Reel8;
Reel8 = Entier.additionner(Reel6, Reel7);
Reel8.afficher();
System.out.println("");
Entier Reel3 = new Entier(20);
Entier Reel4 = new Entier(415);
Entier Reel5;
Reel5 = Entier.multiplier(Reel3, Reel4);
Reel5.afficher();
}
} |
Merci ++