Java:investment equation
Résolu
domxaline
Messages postés
204
Statut
Membre
-
domxaline Messages postés 204 Statut Membre -
domxaline Messages postés 204 Statut Membre -
Bonjour,
j'écris ce programe,quand je rentre le chiffre dans le r:
exemple 0.10
il montre un erreur,aidez moi svp
Enter the value of P:1000
Enter the value of r:0.10
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextFloat(Unknown Source)
at WhileTest.main(WhileTest.java:14)
j'écris ce programe,quand je rentre le chiffre dans le r:
exemple 0.10
il montre un erreur,aidez moi svp
import java.util.Scanner;
public class WhileTest
{
public static void main (String []args)
{
Scanner input=new Scanner(System.in);
System.out.print("Enter the value of P:");
//double p=input.nextDouble();
float p=input.nextFloat();
System.out.print("Enter the value of r:");
//double r=input.nextDouble();
float r=input.nextFloat();
System.out.print("Enter the value of n:");
//double n=input.nextDouble();
float n=input.nextFloat();
float v1=1+r;
float v2=(float) Math.pow(v1,n);
double v=(float)p*v2;
Float d=new Float(v);
System.out.print(d);
}
}
Enter the value of P:1000
Enter the value of r:0.10
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextFloat(Unknown Source)
at WhileTest.main(WhileTest.java:14)
1 réponse
-
Java attend que tu rentres des nombres flottants "à la française" c'est à dire avec une virgule et non un point : r=0,10
Tu peux éventuellement imposer la notation anglosaxone (avec un point) en faisant :input.useLocale(Locale.US);
-
j'ai essayé ça toujours même réponse
Enter the value of P:1000
Enter the value of r:0,10
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextLong(Unknown Source)
at java.util.Scanner.nextLong(Unknown Source)
at WhileTest.main(WhileTest.java:14) -
-