-
java help please
These are the exercise instructions that I had to complete:
When cashiers make change they first try to "fit" dollars into the amount you get back, then try to fit quarters (25 cent coins) into what is left over, they try to fit dimes (10 cent coins) into what is now left over, then try to fit nickels (5 cent coins) into what is left, and finally are left with a few odd cents. For example, say that your change is 163 cents:
• One dollar fits into 163, leaving 63 cents.
• Two quarters fit into 63 cents, leaving 13 cents.
• One dime fits into 13 cents, leaving 3 cents.
• No nickels are needed.
• Three cents are left.
Your change is : 1 dollar, two quarters, one dime, and three cents.
And this is my code:
PHP Code:
import java.util.Scanner;
public class Exercise2 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int amount = 0;
amount = Integer.parseInt(in.nextLine());
int amountleft = amount;
System.out.println("Hello ugly customer, ");
System.out.println("Your change is: ");
int dollarfit = amountleft %100;
amountleft = amountleft - dollarfit;
System.out.println(dollarfit + " dollar(s)fits into " + amount + " cents");
int quarterfit = amountleft % 25;
amountleft = amountleft - quarterfit;
System.out.println(quarterfit + " quarter(s)fits into " + amount + " cents");
int dimefit = amountleft % 10;
amountleft = amountleft - dimefit;
System.out.println(amountleft + " dime(s)fits into " + amount + " cents");
int nicklefit = amountleft % 5;
amountleft = amountleft - nicklefit;
System.out.println(amountleft + " nickle(s)fits into " + amount + " cents");
int centfit = amountleft % 1;
amountleft = amountleft - centfit;
System.out.println(amountleft + " cent(s)fits into " + amount + " cents");
}
}
-
Re: java help please
-
Re: java help please
So err.. is there a problem of some kind?