import java.util.Scanner;
class LinearSearch
{
public static void main(String args[])
{
int c, n, search, array[];
Scanner in = new Scanner(System.in);
System.out.println("n : ");
n = in.nextInt();
array = new int[n];
System.out.println("Masukan angka " + n );
for (c = 0; c < n; c++)
array[c] = in.nextInt();
System.out.println("Angka yang di cari : ");
search = in.nextInt();
for (c = 0; c < n; c++)
{
if (array[c] == search)
{
System.out.println(search + " di array ke- " + (c + 1) + ".");
break;
}
}
if (c == n)
System.out.println(search + "Tidak ada");
}
}
0 comments:
Post a Comment