[java] - 혼자공부하는자바 160p. 확인문제

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package chapter04;
 
import java.util.Scanner;
 
public class breakContinue {
 
    public static void main(String[] args) {
        //160p. 확인문제 2번
        System.out.println("---------------2번-----------------");
        int sum = 0;
        for (int i =1; i<=100; i++)
            if(i%3==0) {
                sum += i;
        }
        System.out.println(sum);
        System.out.println("---------------3번-----------------");        
        //확인문제 3번
        while(true) {    
            int dice1 = (int)(Math.random()*6)+1;
            int dice2 = (int)(Math.random()*6)+1;
            int sum2 = 0;
            System.out.println("눈1="+dice1+",\t눈2="+dice2);
            sum2 = dice1+dice2;
            if(sum2==5) {
                System.out.println("눈1="+dice1+",\t눈2="+dice2+"\t 두 주사위 눈의 합이 5이므로 종료합니다.");
                break;
            }
        }
        System.out.println("---------------4번-----------------");            
        //확인문제 4번
        int res=0;
        int i =1;
        int j =1;
        
        for( i =1; i<=10; i++) {
            for( j=1; j<=10; j++) {
                res = 4*+ 5*j;
                if(res==60)
                System.out.println(i+","+j);
            }
        }
        System.out.println("---------------5번-----------------");        
        //확인문제 5번
        for(int k=1; k<=4;k++) {
            for(int h=1; h<=k; h++) {
                    System.out.print("*");
                }
            System.out.print("\n");
            }
            
 
        System.out.println("---------------6번-----------------");
        //확인문제 6번
        
        for(int k=1; k<=4; k++) {
            for(int n=4; n > k; n--) {
                System.out.print(" ");
            }
            for(int h=1; h <= k; h++) {
                System.out.print("*");
                    }
            System.out.println("\t");
            }
        
        //확인문제 7번
        
        int balance = 0;
        int out_cash = 0;
        int in_cash = 0;
        int process = 0;
        boolean run = true;
        
        Scanner scanner = new Scanner(System.in);
        
        while(run) {
            System.out.println("-----진행할 업무를 선택하세요--------");
            System.out.println("1.예금 | 2.출금 | 3.잔고 | 4.종료");
            process = scanner.nextInt();
            
            if(process == 1) {
                System.out.println("예금하실 금액을 입력해주세요.");
                in_cash = scanner.nextInt();
                balance += in_cash;
            } else if(process == 2) {
                System.out.println("출금하실 금액을 입력해주세요.");
                out_cash = scanner.nextInt();
                balance -= out_cash;
            } else if(process == 3) {
                System.out.println("현재 잔고는 "+balance+"원 입니다.");
            } else if(process == 4) {
                System.out.println("종료되었습니다.");
                break;
            } else {
                System.out.println("잘못선택하셨습니다. 다시 선택해주십시오.");
            }
            
        }
    }
}
    
 
    
 
 
 
 
cs