I was Solving a worded java problem, this is the situation:
Write a class that calculates and displays the conversion of an entered number of peso into currency denominations - 20s, 10s, 5s, and 1s. Save the class as Dollars.java.
I think my code (on the top) have missed something
This is my another code:
mport java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Dollars {
public static void main(String[] args) throws IOException{
BufferedReader Kehn = new BufferedReader(new InputStreamReader(System.in));
int Amnt,Amnt1,Amnt2,Amnt3,Amnt4,Amnt5;
System.out.println("Enter a value in dollar: ");
Amnt = Integer.parseInt(Kehn.readLine());
Amnt5 = Amnt * 20;
Amnt1 = Amnt /20;
Amnt1 %= 20;
Amnt2 = Amnt5 / 10;
Amnt2 %= 10;
Amnt3 = Amnt /5;
Amnt3 %= 5;
Amnt4 = Amnt / 1;
Amnt4 %= 1;
System.out.println(Amnt1);
System.out.println(Amnt2);
System.out.println(Amnt3);
System.out.println(Amnt4);
If i put 100 the result will be:
20s = 5
10s = 0
5s = 0
1s = 0
This is the problem, If i put 50 the result will be:
20s = 2
10s = 1
5s = 0
1s = 0
But my result is:
20s = 2
10s = 0
5s = 0
1s = 0
another, If i put 15 the result will be:
20s = 0
10s = 1
5s = 1
1s = 0
and my result is:
20s = 0
10s = 0
5s = 3
1s = 0
Please help what is the formula to correct my mistakes ^^