<java>ce deux prg donne pas même resultat
domxaline
Messages postés
188
Date d'inscription
Statut
Membre
Dernière intervention
-
domxaline -
domxaline -
Bonjour,
les deux prg suivants donne pas même résultat,aidez moi s'il vous plaît
resultat ce ce prg:
Enter the number of quarters:1
Enter the number of dimes:? 2
Enter the number of nickles:? 3
Enter the number of pennies? 4
The total in dollars is 0.6400000000000001
resultat ce ce prg:
Entrez pour vingtcinq
1
Entrez pour cinquante
2
Entrez pour dix
3
Entrez pour cinq
4
The total en euros 0.01
je veux il additionne
vingtcinq*1;cinquante*2;dix*3;cinq*4
et il divise ce montant par 100
et affiche résultat
les deux prg suivants donne pas même résultat,aidez moi s'il vous plaît
public class Countchange { public static void main(String[] args) { int quarters; int dimes; int nickles; int pennies; double dollars; double total; TextIO.put("Enter the number of quarters:"); quarters=TextIO.getInt(); TextIO.put("Enter the number of dimes:"); dimes=TextIO.getInt(); TextIO.put("Enter the number of nickles:"); nickles=TextIO.getInt(); TextIO.put("Enter the number of pennies"); pennies=TextIO.getInt(); dollars=(0.25*quarters)+(0.10*dimes)+(0.05*nickles)+(0.01*pennies); total=dollars/100.0; TextIO.putln(); TextIO.putln("The total in dollars is "+dollars); } }
resultat ce ce prg:
Enter the number of quarters:1
Enter the number of dimes:? 2
Enter the number of nickles:? 3
Enter the number of pennies? 4
The total in dollars is 0.6400000000000001
import java.util.Scanner; public class Euros { public static void main(String []args) { int vingtcinq=0; int cinquante=0; int dix=0; int cinq=0; double euro=0; double total; System.out.println("Entrez pour vingtcinq"); Scanner sc=new Scanner(System.in); vingtcinq=sc.nextInt(); System.out.println("Entrez pour cinquante"); Scanner sc1=new Scanner(System.in); vingtcinq=sc1.nextInt(); System.out.println("Entrez pour dix"); Scanner sc2=new Scanner(System.in); vingtcinq=sc2.nextInt(); System.out.println("Entrez pour cinq"); Scanner sc3=new Scanner(System.in); vingtcinq=sc3.nextInt(); euro=(0.25*vingtcinq)+(0.50*cinquante)+(0.10*dix)+(0.05*cinq); total=euro/100.0; System.out.println("The total en euros "+total); } }
resultat ce ce prg:
Entrez pour vingtcinq
1
Entrez pour cinquante
2
Entrez pour dix
3
Entrez pour cinq
4
The total en euros 0.01
je veux il additionne
vingtcinq*1;cinquante*2;dix*3;cinq*4
et il divise ce montant par 100
et affiche résultat
A voir également:
- <java>ce deux prg donne pas même resultat
- Waptrick java football - Télécharger - Jeux vidéo
- Jeux java itel - Télécharger - Jeux vidéo
- Resultat foot - Télécharger - Vie quotidienne
- Eclipse java - Télécharger - Langages
- Java apk - Télécharger - Langages
3 réponses
Salut,
Ton problème vient simplement du fait que tuas oublié de changer tes variables : tu utilises toujours la variable vingtcinq...
Attention avec les copié-collé....
System.out.println("Entrez pour vingtcinq");
Scanner sc=new Scanner(System.in);
vingtcinq=sc.nextInt();
System.out.println("Entrez pour cinquante");
Scanner sc1=new Scanner(System.in);
vingtcinq=sc1.nextInt();
System.out.println("Entrez pour dix");
Scanner sc2=new Scanner(System.in);
vingtcinq=sc2.nextInt();
System.out.println("Entrez pour cinq");
Scanner sc3=new Scanner(System.in);
vingtcinq=sc3.nextInt();
Ton problème vient simplement du fait que tuas oublié de changer tes variables : tu utilises toujours la variable vingtcinq...
Attention avec les copié-collé....
System.out.println("Entrez pour vingtcinq");
Scanner sc=new Scanner(System.in);
vingtcinq=sc.nextInt();
System.out.println("Entrez pour cinquante");
Scanner sc1=new Scanner(System.in);
vingtcinq=sc1.nextInt();
System.out.println("Entrez pour dix");
Scanner sc2=new Scanner(System.in);
vingtcinq=sc2.nextInt();
System.out.println("Entrez pour cinq");
Scanner sc3=new Scanner(System.in);
vingtcinq=sc3.nextInt();
le résultat de class Countchange
The total in dollars is 0.6400000000000001
le résultat pour le class Euros
The total en euros 0.0175
les réponse n'est pas le même pour les 2 prgs !!!
c'est pas normal
The total in dollars is 0.6400000000000001
le résultat pour le class Euros
The total en euros 0.0175
les réponse n'est pas le même pour les 2 prgs !!!
c'est pas normal
merci beaucoup j'ai corrigé mon erreur
il faut écrire comme ceci:
il faut écrire comme ceci:
package Textprg; public class Countchange { public static void main(String[] args) { int quarters; int fifty; int dimes; int nickles; double dollars; double total; TextIO.put("Enter the number of quarters:"); quarters=TextIO.getlnInt(); TextIO.put("Enter the number of pennies:"); fifty=TextIO.getlnInt(); TextIO.put("Enter the number of dimes:"); dimes=TextIO.getlnInt(); TextIO.put("Enter the number of nickles:"); nickles=TextIO.getlnInt(); //dollars=(0.25*quarters)+(0.10*dimes)+(0.05*nickles)+(0.01*pennies); dollars=(0.25*quarters)+(0.50*fifty)+(0.10*dimes)+(0.05*nickles); total=dollars/100.0; TextIO.putln(); TextIO.putln("The total in dollars is "+total); } }