-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathCoin_Change.java
More file actions
35 lines (25 loc) · 806 Bytes
/
Coin_Change.java
File metadata and controls
35 lines (25 loc) · 806 Bytes
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
import java.util.Scanner;
import java.util.Vector;
public class Coin_Change {
private static void min(int v,int arr[]) {
int len = arr.length;
Vector<Integer> a = new Vector<>();
for (int i = len - 1; i >= 0; i--) {
while (v >= arr[i]) {
v = v - arr[i];
a.add(arr[i]);
}
}
for (int i = 0; i < a.size(); i++) {
System.out.print(" "+ a.elementAt(i));
}
}
public static void main(String[] args) {
int[] coins = {1, 2, 5, 10, 20, 50};
Scanner scanner = new Scanner(System.in);
System.out.println("Enter amount for change");
int a = scanner.nextInt();
System.out.print("Minimum coin change required:");
min(a,coins);
}
}