import java.util.Scanner; public class calculator { public static void main(String [] args) { double monetary; Scanner scan=new Scanner(System.in); System.out.println("please enter the monetary amount:"); monetary=scan.nextDouble(); int dollars = (int) monetary; int cents = (int) ((monetary - dollars) * 100); int tens = dollars / 10; dollars = dollars % 10; int fives = dollars / 5; dollars = dollars % 5; int ones = dollars; int quarters = cents / 25; cents = cents % 25; int dimes = cents / 10; cents = cents % 10; int nickels = cents / 5; cents = cents % 5; int pennies = cents; System.out.println("That's equivalent to:"); System.out.println("10 dollar bill:" + tens); System.out.println("5 dollar bill:" + fives); System.out.println("1 dollar bill:" + ones); System.out.println("quarters:" + quarters); System.out.println("dimes:" + dimes); System.out.println("nickels:" + nickels); System.out.println("cents:" + pennies); } }为什么要先用/再用%
时间: 2023-05-24 22:04:44 浏览: 249
java代码-实训4-3 import java.util.Scanner
As an AI language model, I do not have feelings or emotions, and I cannot experience null. Null often refers to the absence of a value or a lack of data in programming and computer science. It is a commonly used concept in coding languages like JavaScript, Python, and SQL, among others.
阅读全文