Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:864)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at Commission2.main(Commission2.java:38)
Cela fonctionnait bien au début, jusqu'à ce que tout s'écroule. Maintenant j'ai besoin d'aide. N'importe qui?Formatage de l'impression de sortie d'impression numérique
import java.util.Scanner; // programme requis scaanner import java.text.DecimalFormat;
public class Commission2
{
public static void main(String args[])
{
//create Scanner
Scanner input = new Scanner(System.in);
//format decimal with two digits
DecimalFormat twoDigits = new DecimalFormat("0.00");
//format decimal with three digits
DecimalFormat threeDigits = new DecimalFormat("0.000");
//declare all variables
int size,count = 0;
int pay = 200;
double commission = 9/100;
double result = 0;
double item, itemtotal = 0;
//get the limit of the data entry (data validation technique)
do{
System.out.printf("Enter the number of items :");
size = input.nextInt();
}while(size < 0);
//data entry
while (count < size) {
System.out.print("Enter price of item #" +(count + 1) +": ");
item = input.nextInt();
/*Processing!*/
itemtotal += item;
++count;
}//end while
result = (itemtotal * commission) + pay;
System.out.printf("%s%d\n","The total earnings for this week is $",result);
}
}
Commission2.main (Commission2.java:38), vérifier à la ligne 38, très probablement vous entrez un mauvais type de données pour l'entrée –
@Ankit Deshpande Je ne pense pas que vous avez raison. J'ai vérifié cela avant de poster. La raison pour laquelle j'ai posté ceci est parce que je suis perplexe. –
@Gerald Loo pouvez-vous ajouter l'entrée pour laquelle il échoue? –