반응형

           

  JAVA Study



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
public class tistory {
 
    public static void main(String[] args) {
        
        //3단 출력    
        for(int i=2; i<10; i++){
            System.out.println("3 * "+i+" = "+(3*i));
        }
        
        
        //한 line에 7개 씩 출력
        for(int a=1; a<=31; a++){
            System.out.print(a+"일");
            
            if(a%7==0){
                System.out.println();
            }
        }
        
        
        //if문을 switch문으로 바꾸기
        int a = 10;
        int b = 20;
        int result = 0;
        String value="*";
        
        if(value=="+"){
            result = a+b;
        } else if(value=="-"){
            result = a-b;
        } else if(value=="*"){
            result = a*b;
        } else{
            result = a/b;
        }
        System.out.println(result);
        
        int result2 = 0;
        String value2="+";
        switch(value2){
        case "+" : result2 = a+b;
        break;
        case "-" : result2 = a-b;
        break;
        case "*" : result2 = a*b;
        break;
        case "/" : result2 = a/b;
        break;
        default : result2 = 100;
        }
        System.out.println(result2);
        
        
        //1차원 배열 출력
        int[] bb = {11,12,13};
        for(int i=0; i<bb.length;i++){
            System.out.println(bb[i]);
        }
        
        
        //구구단 1~9단 출력
        for(int i=1; i<10; i++){
            for(int j=2;j<10;j++){
                System.out.println(i+"*"+j+"="+(i*j));
            }
        }
        
        
        //for 문을 이용한 출력
        int[][] numberB={{11,12,13},{71,72,73}};
        for(int i=0; i<numberB.length; i++){
            for(int j=0;j<numberB[i].length;j++){
                System.out.println(numberB[i][j]);
            }
        }
        
        
        //합을 구하시오
        int[][] numberC = {{11,12,13},{71,72,73}};
        int sum=0;
        for(int i=0; i<numberC.length; i++){
            for(int j=0;j<numberC[i].length;j++){
                sum += numberB[i][j];
            }
        }
        System.out.println(sum);
        
        
        //아래의 결과처럼 출력하시오
        //        (결과)
        //        1*
        //        4****
        //        5*****
        
        int[] arr={1,4,5};
        for(int i=0; i<arr.length; i++){
            System.out.print(arr[i]);
            
            for(int j=0; j<arr[i];j++){
                System.out.print("*");
            }
            System.out.println();
        }
    }
}
 
cs


반응형

+ Recent posts