반응형

           

  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
public class tistory {
 
    public static void main(String[] args) {
        int x = 0;
        System.out.printf("x=0 일때, 참인것은",x);
        
        if(x==0){
            System.out.println("x==0"); // 참
        }
        if(x!=0){
            System.out.println("x!=0"); // 거짓
        }
        if(!(x==0)){
            System.out.println("!(x==0)"); //거짓
        }
        if(!(x!=0)){
            System.out.println("!(x!=0)"); //참
        }
        
        x=1;
        System.out.printf("x=1 일때, 참인것은",x);
        
        if(x==0){
            System.out.println("x==0"); // 거짓
        }
        if(x!=0){
            System.out.println("x!=0"); // 참 
        }
        if(!(x==0)){
            System.out.println("!(x==0)"); // 참
        }
        if(!(x!=0)){
            System.out.println("!(x!=0)"); // 거짓
        }
    
    }
}
 
cs



 

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
public class tistory {
 
    public static void main(String[] args) {
        
        //if 문
        int input;
        System.out.print("숫자를 하나 입력하세요.>");
        
        Scanner scn = new Scanner(System.in);
        String tmp = scn.nextLine(); //화면으로 입력받은 내용을 tmp에 저장
        input = Integer.parseInt(tmp); // 입력받은 문자열(tmp)을 숫자로 변환
    
        if(input==0){
            System.out.println("입력한 숫자는 0");
        }
        if(input!=0){
            System.out.printf("입력한 숫자는 "+input); 
        }
 
 
        //if-else 문        
        System.out.print("숫자를 하나 입력하세요>>");
        Scanner scn1 = new Scanner(System.in);
        int input1 = scn1.nextInt();
 
        if(input1==0){
            System.out.println("입력하신 숫자는 0 입니다.");
        } else{
            System.out.println("입력하신 숫자는 0이 아닙니다.");
        }
 
 
        //if-else-if 문
        int score = 0;
        char grade = ' ';
 
        System.out.print("점수를 입력하세요");
        Scanner scn2 = new Scanner(System.in);
        score = scn2.nextInt();
 
        if (score >=90){ 
            grade = 'A';    // score가 90 보다 같거나 크면 A
        } else if (score >=80){
            grade = 'B';    // score가 80 보다 같거나 크면 B
        } else if (score >=70){
            grade = 'C';    // score가 70 보다 같거나 크면 C
        } else if (score >=60){
            grade = 'D';    // score가 60 보다 같거나 크면 D
        } else {
            grade = 'F';    // 나머지는 F
        } 
        System.out.println(score+"점 으로 당신의 학점은"+grade+"입니다.");
 
        //중첩 if문
        int score1 = 0;
        char grade1 = ' ';
        char opt = '0';
        System.out.print("점수를 입력하세요");
        Scanner scn3 = new Scanner(System.in);
        score1 = scn3.nextInt();
        if (score1 >=90){ 
            grade1 = 'A';    // score가 90 보다 같거나 크면 A
            if (score1 >=98){
                opt = '+';    // 90이상 중 98이상은 A+
            } else if (score1 <94){
                opt = '-';    // 90이상 중 94미만은 A-
            }
 
        } else if (score1 >=80){
            grade1 = 'B';    // score가 80 보다 같거나 크면 B
 
 
        } else if (score1 >=70){
            grade1 = 'C';    // score가 70 보다 같거나 크면 C
 
 
        } else if (score1 >=60){
            grade1 = 'D';    // score가 60 보다 같거나 크면 D
 
 
        } else {
            grade1 = 'F';    // 나머지는 F
 
 
        } 
        System.out.println(score1+"점 으로 당신의 학점은"+grade1+opt+"입니다.");
 
    }
}
cs
반응형

+ Recent posts