import java.util.Scanner; // Invoke an external class to insert a scanner
public class money {
public static void main(String[] args) {
// // TODO Auto-generated method stub
String input;
Scanner sc = new Scanner (System.in); //Scanner
int [] unit = {50000,10000,5000,1000,500,100,50,10,1}; // type of money to convert
int money; //money variable
System.out.printf ("Enter Amount:");
money = sc.nextInt(); // received the amount (integer)
for(int i=0; i<unit.length; i++) {
System.out.printf("%d circle: %d,", unit[i], money/unit[i]);
money=money - (money/unit[i])*unit[i];//Remaining money = total money- (money before previous calculation/current share of i)*\
{System.out.println ("Do you want to continue? : ");
input = sc.next();
if(input.equalsIgnoreCase("q"))
break;
else
continue;}
}
sc.close();
}
}
When running with eclipse
Enter the amount: 12345676
KRW 50000: 246, do you want to continue? :
1
10,000 won: 4 pieces, do you want to continue? :
2
5000 won: 1 piece, do you want to continue? :
3
It comes out like this
amount:
123456
50000 won: 2 pieces, 10000 won: 2 pieces, 5000 won: 0 pieces, 1000 won: 3 pieces, (omitted)
Would you like to go on? :
q
It's over.
I want to make it like this. How should I modify it? ㅠ<
java loops
Don't ask me if I'm going to continue or not, but try to fix the loop to repeat up to 1,000 won:
for (int i=0; i<unit.length; i++) {
System.out.printf("%d circle: %d,", unit[i], money/unit[i]);
money=money - (money/unit[i])*unit[i];//Remaining money = total money- (money before previous calculation/current share of i)*\
if (Is it a_loop with 1,000 won_unit output) {
System.out.println ("Do you want to continue? : ");
input = sc.next();
if (input.equalsIgnoreCase("q")) {
break;
}
}
}
It seems like homework, so I just gave you a hint.
© 2024 OneMinuteCode. All rights reserved.