JAVA

JAVA기본_연산자

ChoiSH313 2018. 12. 31. 17:45
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
package org.opentutorials.javatutorials.operator;
 
public class operator {
 
    public static void main(String[] args) {
        // 연산자
        int result = 1+2;
        System.out.println(result);
        
        result = result - 1;
        System.out.println(result);
        
        result = result * 2;
        System.out.println(result);
        
        result = result / 2;
        System.out.println(result);
        
        result = result % 3;
        System.out.println(result); // 나눴을때 나머지
        
        // 연산자의 형변환
        String first = "choi";
        String second = "sung ho";
        String last = first + second;
        System.out.println(last);
        
        int a = 10;
        int b = 3;
        
        float c = 10.0F;
        float d = 3.0F;
        
        System.out.println(a/b);
        System.out.println(c/d);
        System.out.println(a/d); //int가 float로 자동 형변환
        
        // 단항 연산자
        int i = 0;
        i++;
        System.out.println(i);
        ++i;
        System.out.println(i);
        System.out.println(++i);
        System.out.println(i++);
        System.out.println(i);
        
 
    }
 
}
 
cs