1
import java.text.NumberFormat;
import java.text.DecimalFormat;
import java.util.Scanner;
public class Part2 {
public static void main(String []args) {
Scanner input = new Scanner(System.in);
NumberFormat money = NumberFormat.getCurrencyInstance();
DecimalFormat decimalformat = new DecimalFormat("##0; ##0");
double a, b, answer;
double nOnebills, nFivebills, nTenbills;
double nTwentybills, nFiftybills, nOnehundredbills;
double int nPenny, nNickle, nDime, nQuarter;
System.out.println("Please input the amount the customer owns.");
a = input.nextDouble();
System.out.println("Please input the amount the customer paid.");
b = input.nextDouble();
answer = a - b;
System.out.println("The amount of change given back to the customer "+
money.format(answer));
nOnehundredbills = (answer)/(100);
if (nOnehundredbills <= 0) {
System.out.println("The number of hundred dollar bills in your change is 0");
} else {
System.out.println("The number of hundred dollar bills in your change is "+ nOnehundredbills);
}
}
}
は、出力はこのでした:私のドル計算機は、私がJavaでそれをしたいのとまったく同じではありませんか?
Please input the amount the customer owns.
100
Please input the amount the customer paid.
200
The amount of change given back to the customer ($100.00)
The number of hundred dollar bills in your change is 0
0は100で割った100以来の1であるべき1で、1ので、それは、elseステートメントに行っているはずですゼロ以下ではありません。
この条件を再確認する必要があります。if(nOnehundredbills <= 0) System.out.println( "変更した100ドル紙幣の数は です)"; 他 のSystem.out.println(+ nOnehundredbills「あなたの変更で百ドル紙幣の数が である」); ' は**あなたのコードの答えに= -100 ** –
2種類の二重宣言し、ここではint型ている理由"double int nPenny、nNickle、nDime、nQuarter"?あなたのコードはコンパイルされますか? –
お客様が自分よりも多くを支払っています... – Stefan