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);
}
}
}
输出是:
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应该是1,因为100除以100是1而1不小于或等于零所以它应该转到else语句。
答案 0 :(得分:1)
你应该写
answer =b-a;//not a-b
自您撰写a-b
后,答案的值为-1
,
肯定会输入第一个if语句,因为-1<=0
。