Last active
September 22, 2016 14:49
-
-
Save devetude/3eaac55b8894915ee0ea52f19212310d to your computer and use it in GitHub Desktop.
순차탐색 알고리즘 2 (Sequential Search 2)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
/** | |
* 순차탐색 알고리즘 2 (Sequential Search 2) | |
* | |
* @author devetue | |
*/ | |
public class Main { | |
public static void main(String args[]) { | |
Scanner sc = new Scanner(System.in); | |
int N = sc.nextInt(); | |
int[] arr = new int[N]; | |
for (int i = 0; i < N; i++) { | |
arr[i] = sc.nextInt(); | |
} | |
int K = sc.nextInt(); | |
int kIndex = -1; | |
for (int i = 0; i < N; i++) { | |
if (arr[i] == K) { | |
kIndex = i; | |
System.out.println("K's index is " + kIndex + "."); | |
break; | |
} | |
} | |
if (kIndex == -1) { | |
System.out.println("There isn't K here."); | |
} | |
sc.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment