-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChange.java
46 lines (34 loc) · 1.16 KB
/
Change.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.util.Scanner;
public class Change
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in); //creating Scanner class object
String name;
int n;
System.out.println("Welcome to the smart Change Machine");
System.out.println("-----------------------------------");
System.out.print("Your name: ");
name = in.nextLine(); //scanning name
System.out.print("Change amount in cents: ");
n = in.nextInt(); //scanning cents
int halfDollar = n / 50; //calculating half a dollar
n = n%50;
int quarter = n / 25; //calculating quarters
n = n%25;
int dime = n / 10; //calculating dimes
n = n%10;
int nickel = n / 5; //calculating nickels
n = n%5;
int penny = n; //the remainder is pennies
//printing output
System.out.println("\nChange coins due:");
System.out.println("-----------------");
System.out.println("Half dollars: "+halfDollar);
System.out.println("Quarters: "+quarter);
System.out.println("Dimes: "+dime);
System.out.println("Nickels: "+nickel);
System.out.println("Pennies: "+penny);
System.out.println("\nGood Bye!");
}//end of main
}//end of class