-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCandySwap.java
More file actions
39 lines (27 loc) · 936 Bytes
/
Copy pathCandySwap.java
File metadata and controls
39 lines (27 loc) · 936 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
34
35
36
37
38
39
import java.util.Scanner;
public class CandySwap {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int initCandies;
System.out.println("How many candies are there initially?");
initCandies = input.nextInt();
int exchangeCost;
System.out.println("How many wrappers does it cost to get one piece of candy?");
exchangeCost = input.nextInt();
printCandies(initCandies,exchangeCost);
input.close();
}
public static void printCandies(int initialCandies, int exchangeCost)
{
int initCandies = initialCandies;
int currentWrappers = initialCandies;
int newWrappers = 0;
while (currentWrappers >= exchangeCost)
{
newWrappers++;
currentWrappers-=exchangeCost -1;
}
System.out.println("Total candies: " + (initCandies + newWrappers));
System.out.println("# of wrapper remainders: " + currentWrappers);
}
}