Write a program that reads three integer values from the keyboard using the Scanner class representing, respectively, a number of quarters, dimes, and nickels. Convert the total coin amount to dollars and output the result.Write a program that reads three integer values from the keyboard using the Scanner class representing, respectively, a number of quarters, dimes, and nickels. Convert the total coin amount to dollars and output the result.
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner scan= new Scanner(System.in);
System.out.print("Enter number of quarters ");
int quarters = scan.nextInt();
System.out.print("Enter number of dimes ");
int dimes = scan.nextInt();
System.out.print("Enter number of nickels ");
int nickels = scan.nextInt();
float cents = quarters*25 + dimes*10 + nickels*5; // Quarter is 25 cents, Dime is 10 cents , Nickel is 5 cents
float dollars = cents/100;
System.out.println("Dollars: " + dollars );
scan.close();
}
}
Output:
Get Answers For Free
Most questions answered within 1 hours.