Write an application named Coins that asks the user to enter one integer represe
ID: 3789094 • Letter: W
Question
Write an application named Coins that asks the user to enter one integer representing a monetary value in cents. The application prints to the screen the equivalent breakdown in quarters, dimes, nickels and cents. (Java) Write an application named Coins that asks the user to enter one integer representing a monetary value in cents. The application prints to the screen the equivalent breakdown in quarters, dimes, nickels and cents. (Java) Write an application named Coins that asks the user to enter one integer representing a monetary value in cents. The application prints to the screen the equivalent breakdown in quarters, dimes, nickels and cents. (Java)Explanation / Answer
import java.util.*;
public class HelloWorld{
public static void main(String []args){
Scanner input=new Scanner(System.in); //for taking the input from the user
System.out.println("Enter the integer representing a monetary value in cents :");
int cents=input.nextInt(); //storing the input into variable cents
int quarters = Math.round((int)cents/25); //converting cents into quarters
int change=cents%25; //taking the remainder and storing in variable change
int dimes = Math.round((int)change/10); //converting the remainder into dimes
change=change%10; //again taking the remainder
int nickels = Math.round((int)change/5); //converting the remainder into nickles
System.out.println("Cents: " + cents); //printing cents
System.out.println("Quarters: " + quarters); //printing quarters
System.out.println("Dimes: " + dimes); //printing dimes
System.out.println("Nickels: " + nickels);//printing nickels
}
}
/********OUTPUT**********
Enter the integer representing a monetary value in cents :
55
Cents: 55
Quarters: 2
Dimes: 0
Nickels: 1
**********OUTPUT**********/
/* Note:Please do ask in case of any confusion,Thanks */
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.