2017-09-20 1 views
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ステートメントに行っているはずですゼロ以下ではありません。

+0

この条件を再確認する必要があります。if(nOnehundredbills <= 0) System.out.println( "変更した100ドル紙幣の数は です)"; 他 のSystem.out.println(+ nOnehundredbills「あなたの変更で百ドル紙幣の数が である」); ' は**あなたのコードの答えに= -100 ** –

+0

2種類の二重宣言し、ここではint型ている理由"double int nPenny、nNickle、nDime、nQuarter"?あなたのコードはコンパイルされますか? –

+0

お客様が自分よりも多くを支払っています... – Stefan

答えて

1

あなたがa-bを書いたので、答えは間違いなく-1<=0ので、最初のif文を入力します-1の値、 を持つことになります

answer =b-a;//not a-b 

を記述する必要があります。

関連する問題