๋ช ํ ์๋ฐ ํ๋ก๊ทธ๋๋ฐ 3์ฅ 145์ชฝ ์ฒดํฌ ํ์_์ ๋ต
luxury java programming ch3 p145 check time correct answer
1๋ฒ
๋ต: 3๋ฒ int a [] = new int [5];
1. X // ๋ฐฐ์ด์ new ์ฐ์ฐ์๋ก ์์ฑํ ๋, [] ๋๊ดํธ ์์ ํฌ๊ธฐ ์ง์ ํด์ผํ๋ค.
2. X // C/C++๊ณผ ๋ฌ๋ฆฌ ๋ฐฐ์ด ์ ์ธ ์ ํฌ๊ธฐ ์ง์ ํ ์ ์๋ค.
3. O // int [] a = new int [5]; ์ ๊ฐ๋ค.
4. X // C/C++๊ณผ ๋ฌ๋ฆฌ ๋ฐฐ์ด ์ ์ธ ์ ํฌ๊ธฐ ์ง์ ํ ์ ์๋ค.
2๋ฒ
๋ต:
| 
 1 
 | 
 int[][] arr = new int[2][3]; 
 | 
cs | 
๋๋
| 
 1 
 | 
 int arr[][] = new int[2][3]; 
 | 
cs | 
// 2์ฐจ์ ๋ฐฐ์ด์ ๋๊ดํธ๋ฅผ 2๊ฐ ์ฌ์ฉํ์ฌ ์ ์ธ ๋ฐ ์์ฑํ๋ค.
3๋ฒ
๋ต: char[], return c;
// ๋ฉ์๋์ ๋ฐฐ์ด ๋ฆฌํด์ ๋ฐฐ์ด ๊ฐ์ฒด ์ ์ฒด๋ฅผ ๋ณต์ฌํ์ฌ ๋ฆฌํดํ๋ ๊ฒ์ด ์๋๋ผ, ๋ ํผ๋ฐ์ค ๊ฐ์ด ๋ฆฌํด๋๋ค.
4๋ฒ
๋ต:
๋ฐฉ๋ฒ 1 ๊ฐ ํ์ ๋ํ ๋ฐฐ์ด ๊ฐ์ฒด ๊ฐ๊ฐ ์์ฑ ํ, ์์์ ๊ฐ๊ฐ ๊ฐ ๋์ ํ์ฌ ์ด๊ธฐํ
| 
 1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
 | 
 public class P145_4_1 { 
    public static void main(String[] args) { 
        // ๋ฐฉ๋ฒ 1 ๊ฐ ํ์ ๋ํ ๋ฐฐ์ด ๊ฐ์ฒด ๊ฐ๊ฐ ์์ฑ ํ, ์์์ ๊ฐ๊ฐ ๊ฐ ๋์
ํ์ฌ ์ด๊ธฐํ 
        // ๋ฐฐ์ด ์ ์ธ ๋ฐ ์์ฑ 
        int[][] intArray = new int[4][]; 
        intArray[0] = new int[4]; 
        intArray[1] = new int[1]; 
        intArray[2] = new int[1]; 
        intArray[3] = new int[4]; 
        int value = 0; 
        // ์ด๊ธฐํ ๋ฐ ์์ ์ถ๋ ฅ 
        for(int i = 0; i < intArray.length; i++) { 
            for(int j = 0; j < intArray[i].length; j++) { 
                intArray[i][j] = value++; 
                System.out.print(intArray[i][j] + "\t"); 
            } 
            System.out.println(); 
        } 
    } 
} 
 | 
cs | 
๋ฐฉ๋ฒ 2 ๋ฐฐ์ด ์ ์ธ ๋์์ ์ด๊ธฐํ ๋ธ๋ญ์ผ๋ก ๊ฐ ๋์ ํ์ฌ ์ด๊ธฐํ
| 
 1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
 | 
 public class P145_4_2 { 
    public static void main(String[] args) { 
        // ๋ฐฉ๋ฒ 2 ๋ฐฐ์ด ์ ์ธ ๋์์ ์ด๊ธฐํ ๋ธ๋ญ์ผ๋ก ๊ฐ ๋์
ํ์ฌ ์ด๊ธฐํ 
        // ๋ฐฐ์ด ์ ์ธ ๋ฐ ์์ฑ ๋์์ ์ด๊ธฐํ 
        int[][] intArray = { 
                {0, 1, 2, 3}, 
                {4}, 
                {5}, 
                {6, 7, 8, 9} 
        }; 
        // ์์ ์ถ๋ ฅ 
        for(int i = 0; i < intArray.length; i++) { 
            for(int j = 0; j < intArray[i].length; j++) { 
                System.out.print(intArray[i][j] + "\t"); 
            } 
            System.out.println(); 
        } 
    } 
} 
 | 
cs | 
// ๋น์ ๋ฐฉํ ๋ฐฐ์ด ์ ์ธ ๋ฐ ์์ฑ๊ณผ ์ด๊ธฐํ๋ ์ด๊ธฐํ ๋ธ๋ญ์ ์ด์ฉํ๋ฉด new ์ฐ์ฐ์๋ฅผ ์ด์ฉํ์ฌ ๋ฐฐ์ด ๊ฐ์ฒด๋ฅผ ์์ฑํ๋ ๋ฐฉ๋ฒ๋ณด๋ค ๊ฐ๋จํ๊ฒ ํ ์ ์๋ค.