출처: https://bumcrush.tistory.com/182 [맑음때때로 여름]
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
40
         int a; // =3240; // 지불해야할 금액
         int b; //=10000; // 본인이 낸 금액
         
         Scanner money=new Scanner(System.in);
         System.out.print("지불해야할 금액 : ");
         a=money.nextInt();
         System.out.print("낸 금액 : ");
         b=money.nextInt();
         
         
         int c; // 거스름돈
         c=b-a; 
    
         int d,e,f,g,h,i; // 5000원 1000원 500원 100원 50원 10원의 갯수
         
         
         
        /* d=c/5000; // 5000원권의 갯수
         e=(c-(d*5000))/1000; // 1000원권의 갯수
         f=(c-(d*5000)-(e*1000))/500 ;// 500원 갯수
         g=(c-(d*5000)-(e*1000)-(f*500))/100 ; // 100원 갯수
         h=(c-(d*5000)-(e*1000)-(f*500)-(g*100))/50; // 50원 갯수
         i=(c-(d*5000)-(e*1000)-(f*500)-(g*100)-(h*50))/10; // 10원 갯수 */
         
         d=c/5000;
         e=(c%5000)/1000;
         f=(c%1000)/500;
         g=(c%500)/100;
         h=(c%100)/50;
         i=(c%50)/10;
         
         
         System.out.println("5000원 갯수 = " + d);
         System.out.println("1000원 갯수 = " + e);
         System.out.println("500원 갯수 = " + f);
         System.out.println("100원 갯수 = " + g);
         System.out.println("50원 갯수 = " + h);
         System.out.println("10원 갯수 = " + i); 
    
         
cs

+ Recent posts