我的任務需要我讀取用戶輸入的數字並輸出數字生成的硬幣。例如,如果用戶輸入「37」,程序應該回應(1季度,1毛錢和2便士)。錢幣變化計算
這是迄今爲止我已經得到了我會很感激,如果有人可以幫助我完成它,以及看我當前的代碼有follwing可以使用任何錯誤
import java.util.Scanner;
public class Coin
{
Scanner sc = new Scanner (System.in);
Int n = sc.nextInt("Enter a positive integer");
int number1, number2; // Division operands
int quotient; // Result of division
public static int getQuarters(int cents) {
return Math.floor(cents/25.0);
}
public static int getDimes(int cents) {
return Math.floor(cents/10.0);
}
public static int getNickels(int cents) {
return Math.floor(cents/5.0);
}
public static int getPennies(int cents) {
return Math.floor(cents/1.0);
}
public static void main(String[] args) {
int cents = 46;
int left = cents;
int quarters = getQuarters(cents);
int left -= quarters * 25;
int dimes = getDimes(left);
left -= dimes * 10;
int nickels = getNickels(left);
left -= nickels * 5;
int pennies = left;
System.out.println(cents + " cents = " + quarters + " Quarters, " + dimes + " Dimes, " + nickels + " Nickels, and " + pennies + " Pennies."); // print the output
}
}
你面臨的問題是什麼? –