(9) 문제

JAVA/간단한 코드 2018. 10. 28. 20:16
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 Studypackage;
 
import java.util.Scanner;
 
public class studyclass 
{
    
    public static void main(String[] args)
    {
        int i = 0;
        Scanner sc = new Scanner(System.in);
        String[] names = {"gildong","sooni","culsu","순이","길동","봉순이","영희"};
        
        
        System.out.print("찾는 이름은 >>> ");
        String find = sc.nextLine();


        System.out.println();
        
        System.out.println("equals 검색");
        for(i=0; i < names.length;i++)
        {
            if(names[i].equals(find))
                {
                    System.out.println("찾는 이름은 " + i + " 번째에 있습니다.");
                    break;
                }
            if(i == names.length)
                {
                    System.out.println("찾는 이름은 없습니다.");
                }    
        }
        System.out.println();


        System.out.println("contain 검색");
        
        boolean flag = false;        // contains 결과가 포함 문자열이 있으면 true
        
        for(i=0; i < names.length; i++)        // contains 결과가 포함 문자열이 있으면 true
        {
            if(names[i].contains(find))
            {
                System.out.println("찾는 이름은 " + i + "번째에 있습니다.");
                flag = true;
            }    
        }
        
            if(flag == false)
            {
                System.out.println("찾는 이름은 없습니다.");
            }

    }
}
 
cs


'JAVA > 간단한 코드' 카테고리의 다른 글

(11) 문제  (0) 2018.10.30
(10) 문제  (0) 2018.10.29
(7) 문제  (0) 2018.10.24
(5) 문제  (0) 2018.10.22
(4) 문제  (0) 2018.10.21

설정

트랙백

댓글