๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ’ป ํ”„๋กœ๊ทธ๋ž˜๋ฐ/JAVA

2-2 ์‚ฐ์ˆ ์—ฐ์‚ฐ, ์น˜ํ™˜์—ฐ์‚ฐ, ๋ˆ„์ , ์ฆ๊ฐ, ๋ถ€ํ˜ธ



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
package pack;
 
public class Test2 {
 
    public static void main(String[] args) {
        // ์‚ฐ์ˆ  ์—ฐ์‚ฐ์ž
        int a = 5// = ์น˜ํ™˜ ์—ฐ์‚ฐ์ž (์šฐ์„ ์ˆœ์œ„๊ฐ€ ๊ฐ€์žฅ ๋‚ฎ์Œ)
        int b = 3;
        int c = a + b;
        
        System.out.println(a + b);
        System.out.println(a - b);
        System.out.println(a * b);
        System.out.println(a / b); //๋ชซ์„ ์ทจํ•จ
        System.out.println(a % b); //๋‚˜๋จธ์ง€๋ฅผ ์ทจํ•จ
        System.out.println(a / (double)b);//๋ชซ๊ณผ ๋‚˜๋จธ์ง€
        System.out.println(a / 0.0); //๋ฌดํ•œ๋Œ€ ๊ฐ’
        System.out.println(a % 0.0); //NaN
        
        System.out.println(3 + 4 * 5); // ๊ณฑํ•˜๊ธฐ ๋‚˜๋ˆ„๊ธฐ๊ฐ€ ๋”ํ•˜๊ธฐ ๋นผ๊ธฐ ๋ณด๋‹ค ์—ฐ์‚ฐ ์ˆœ์œ„๊ฐ€ ๋†’์Œ!
        System.out.println((3 + 4* 5); // ์šฐ์„ ์ˆœ์œ„๋ฅผ ๋ณ€๊ฒฝํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๊ด„ํ˜ธ(๋“ค) ๋ฅผ(์„) ์‚ฌ์šฉํ•จ
        
        
        String ss1 = "๋Œ€ํ•œ";
        String ss2 = "๋ฏผ๊ตญ";
        String ss3 = ss1 + ss2; //๋ฌธ์ž์—ด ๋”ํ•˜๊ธฐ(๋„ ๊ฐ€๋Šฅํ•˜๋‹ค)
        System.out.println(ss3);
        System.out.println(ss3 + " " + 82); //๋ฌธ์ž์™€ ์ˆซ์ž๊ฐ€ ๋ฌธ์ž์—ด ๋”ํ•˜๊ธฐ์— ์ฐธ์—ฌํ•˜๋ฉด ์ˆซ์ž๊ฐ€ ๋ฌธ์žํ™” ๋œ๋‹ค.
        System.out.println(ss3 + " " + (80 + 2)); //๊ด„ํ˜ธ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ˆซ์ž๋กœ์„œ ์ž…๋ ฅ๋ฐ›์€ ๊ฐ’์„ ์šฐ์„  ์‚ฐ์ˆ ์ ์œผ๋กœ ์ฒ˜๋ฆฌํ›„ ๋ฌธ์ž์  ๋”ํ•˜๊ธฐ๋ฅผ ํ•œ๋‹ค.
        
        String ss4 = "5" + 6//๋‘˜์ค‘ ๊ฐ’์ด ํ•˜๋‚˜๋ผ๋„ ๋ฌธ์ž๋ผ๋ฉด ๋ฌธ์ž๋กœ ๋จผ์ € ์ฒ˜๋ฆฌ
        System.out.println(ss4 );
        int ia = Integer.parseInt("5"+ 6;     //์ˆซ์žํ™”
        System.out.println(ia);
        
        String ss5 = Integer.toString(5+ 6;    //๋ฌธ์žํ™” 
        System.out.println(ss5);
        
        //๋ˆ„์ 
        System.out.println();
        int no = 1;
        no = no + 1;
        no += 1;
        no++//์ฆ๊ฐ์—ฐ์‚ฐ์ž
        ++no;
        System.out.println("๋ˆ„์ ๊ฐ’์€ " + no + " '์ฆ๊ฐ์—ฐ์‚ฐ์ž ๊ณต๋ถ€์ค‘'");
        
        //์ฆ๊ฐ ์—ฐ์‚ฐ์ž์— ๊ด€ํ•˜์—ฌ 
        System.out.println();
        int imsi = 5;
        int result = ++imsi + 1;
        System.out.println(imsi);
        System.out.println(result);
        
        int imsi2 = 5;
        int result2 = imsi2++ + 1// ++๊ฐ€ imsi2 + 1์„ ์ฒ˜๋ฆฌํ•˜๊ณ  result2์— ์น˜ํ™˜์„ ํ•œ ๋งจ๋’ค์— ํ•˜๋‚˜๋ฅผ ์ถ”๊ฐ€๋œ๋‹ค.        
        System.out.println(imsi2); // ๊ทธ๋ž˜์„œ ์—ฐ์‚ฐ์ฆ๊ฐ์ž๊ฐ€ ๋‹ค๋ฅธ ์ˆซ์ž ์—ฐ์‚ฐ๊ณผ ํ•จ๊ป˜ ํ•˜์ง€ ์•Š๋Š”๋‹ค.
        System.out.println(result2);
        
        //๋ถ€ํ˜ธ์— ๊ด€ํ•˜์—ฌ
        System.out.println();
        int imsi3 = 3;
        System.out.println(imsi3);
        System.out.println(-imsi3);
        System.out.println(imsi3 * -1);        
    }
}
 
cs


๋ฐ˜์‘ํ˜•