Skip to content

Instantly share code, notes, and snippets.

@devetude
Last active September 22, 2016 14:49
Show Gist options
  • Save devetude/3eaac55b8894915ee0ea52f19212310d to your computer and use it in GitHub Desktop.
Save devetude/3eaac55b8894915ee0ea52f19212310d to your computer and use it in GitHub Desktop.
순차탐색 알고리즘 2 (Sequential Search 2)
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