출처: 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
char arrch[] = {'D''W''O''A','B'}; 
// A를 찾아서 a로 변경하고 출력하라 
 
 
//for문으로 
        for (int i=0 ; i < arrch.length ; i++) { 
            if(arrch[i]=='A') { 
                arrch[i]='a'
                System.out.print(arrch[i]);}
            else { 
                System.out.print(arrch[i]);} // DWOaB로 출력
    } 
 
 
System.out.println(""); 
 
//foreach문으로
        
        char arrch1[] = {'D''W''O''A','B'};
        
        
        int index=0 ; // 따로 변수를 줌
        
        for(char c : arrch1) {
            if(c == 'A') {
                arrch1[index] = 'a';
            }
            index++;
        }
        
        for(int i=0; i<arrch1.length;i++) {
            System.out.print(arrch1[i]);
        }
        
 
 
cs

+ Recent posts