반응형

           

  JAVA Study





- if문 


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
public class tistory {
 
    public static void main(String[] args) {
        
        int a = 10;
        
        if(a==10){ 
            // a가 10과 같을 경우 블럭{} 안의 내용 실행
            System.out.println("a의 값은 10 입니다.");
        }
        
        String b = "success";
        
        if(b.equals("success")){
            // b가 success와 같을 경우 블럭 {} 안의 내용 실행
            System.out.println("b는 success입니다.");
        }
        
        String str1 = "good";
        String str2 = "good";
        
        if(str1.equals(str2)){
            System.out.println("같음"); // 같음 출력
        } else{
            System.out.println("다름");
        }
        
        
    }
 
}
cs



- if~else if 문


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
public class tistory {
 
    public static void main(String[] args) {
        
        int a = 10;
        if(a > 10){ 
            // a가 10보다 클 경우 블럭{} 안의 내용 실행
            System.out.println("a의 값은 10보다 크다.");
        } else if(a < 10){
            // a가 10보다 작을 경우 블럭{} 안의 내용 실행
            System.out.println("a의 값은 10보다 작다.");
        } else{
            // 위의 두 조건이 모두 거짓일 경우 실행
            System.out.println("a의 값은 10 이다.");
        }
//===============================================================                
        int b = 20;
        int c = 30;            
        if(b > c){ 
            // b>c가 참이면 블럭{} 안의 내용 실행
            System.out.println("b>c");
        } else if(b < c){
            // b<c가 참이면 블럭{} 안의 내용 실행
            System.out.println("b<c");
        } else{
            // 위의 두 조건이 모두 거짓일 경우 실행
            System.out.println("b=c");
        }
//===============================================================    
        String msg = "";
        int kor = 65;
        int eng = 70;
        
        if(kor>=60 && eng>=60){
            msg = "합격"// kor와 eng 모두 >=60 일경우 출력
        } else if(kor<60 && eng<60) {
            msg = "불합격"// kor와 eng 모두 <60 일경우 출력
        }
        else{
            msg = "재시험";
        }
        
        System.out.println(msg); //합격 출력    
    }
 
}
cs


 


- switch문


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public class tistory {
 
    public static void main(String[] args) {
 
        String pgCode="a_102";
        String msg ="";
        
        switch(pgCode){
        
            case"a_101" : msg="java";
            break;
            
            case"a_102" : msg="jsp";
            break;
            
            case"a_103" : msg="php";
            break;
            
            default: msg="없음";
        }
        System.out.println(pgCode+":"+msg);
    }
}
cs



- for문


1
2
3
4
5
6
7
8
9
10
public class tistory {
 
    public static void main(String[] args) {
        
        for(int i=1; i<=12; i++){
            System.out.println(i+"월"); // 1월~12월
        }
    }
}
 
cs




- while문 


1
2
3
4
5
6
7
8
9
10
11
12
public class tistory {
 
    public static void main(String[] args) {
        int i = 1;
        while(i<=31){
            // i가 1부터 31까지 while문을 실행
            System.out.println(i+"일"); //1일 ~31일 출력
            i++
        }
    }
}
 
cs




반응형

+ Recent posts