Program pencarian skuensial dengan java


import java.util.*;
public class sqsearch
{
public static void main(String [] args)
{
 Scanner wew = new Scanner(System.in);
  int A[]= {9,5,3,7,68,54,89,34,56};
  System.out.print("Cari : ");
  int cari = wew.nextInt();
  int indeks =0;
  while((indeks < 8) && (cari!=A[indeks]))
  {
  indeks++;
  }
  if(cari == A[indeks])
  {
  System.out.println(cari+" ada pada urutan ke "+(indeks+1));
  }
  else
  {
  System.out.println(cari+" tidak ditemukan ");
  }
}
}



Post a Comment

0 Comments