Pourrait on me dire comment on trouve x puissance y avec ce calcul ?
pour x = 4;
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 public class calculxy { public static void main (String[] args) { int x,y; int res=1; Terminal.ecrireStringln("entrer le chiffre à multiplier: "); x = Terminal.lireInt(); Terminal.ecrireStringln("entrer l'exposant: "); y = Terminal.lireInt(); for (int i=1; i<=y; i++){ res = res*x; } Terminal.ecrireInt(x); Terminal.ecrireStringln(" puissance "+y+" vaut "+res); } }
et y = 3;
moi je trouve
res = res * x; c'est à dire :
3 = 3*4 = 12 et non pas 64 ???? ou bien me tromperais je ?
Partager