출처: https://bumcrush.tistory.com/182 [맑음때때로 여름]

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
90
        
        /*  Array(배열) : 같은 자료형 변수들의 묶음.
         형식 :    자료형    배열변수명[] = new 자료형[배열의총수]
                int    arr[]= new int[5]
                int[] arr= new int[3]
                int []arr = new int[3]
        
            arr[index number] = 값
            arr[0]~arr[4] 
            
            초기화 int arr[]=null;
        */
        // 5명 학생의 국어점수 총점, 평균 구하기
        
        int lang1, lang2, lang3, lang4, lang5;
        
        lang1=90;
        lang2=85;
        lang3=100;
        lang4=95;
        lang5=75;
        
        int sum = 0 ;
        
        sum= lang1 + lang2 + lang3 + lang4 + lang5;
        
        double avg=0;
        
        avg =sum/5;
        
        // 배열로 구해보기
        
        int arrlang[] = new int[5]; 
 
        /* int arrlang[];
         arrlang = new int[5]; */
        
        arrlang[0= 90;
        arrlang[1= 85;
        arrlang[2= 100;
        arrlang[3= 95;
        arrlang[4= 75;
        
        
        System.out.println(arrlang[3]);
        
        
    //배열초기화
        int arrnum[]= {9010085};
                
        // char arrchar[] = { 'A','B','C'}; 선언과동시에 초기화하기
        
        char arrchar[];
        // arrchar = { 'A','B','C'} 불가능
        
        arrchar=new char[3]; // 동적할당을 한 이후에 초기화 가능, 선언과 동시에 초기화해야함
        arrchar[0]='A';
 
                
    //alias(별명)
                
            int array[]= {11,22,33};
            int alias[]=array;
            
            System.out.println(alias[2]); // =33
            
            alias[2]=222;
            System.out.println(alias[2]); // =222
            System.out.println(array[2]); // =222
            
    //swap 
            
            int a[] = {1,2,3};
            int b[] = {4,5,6};
            int temp;
            
            /*temp=a[0];
            a[0]=b[0];
            b[0]=temp; */ 
            
            int aliA[]=a;
            int aliB[]=b;
            int alitemp[];
            
            alitemp=aliA;
            aliA=aliB;
            aliB=alitemp;
            
            System.out.println(aliB[0]);
    
cs

+ Recent posts