Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pertemuan3;
- import java.util.Scanner;
- public class nomor1{
- public static int index(int data[], int key){
- for(int i=0;i<data.length;i++){
- if(data[i] == key){
- return i;
- }
- }
- return -1;
- }
- public static void main(String[]args){
- int[] data= {12, 90, 77, 13, 36, 39, 9, 89, 99, 1, 30, 27};
- Scanner in = new Scanner(System.in);
- System.out.print("Data : ");
- for (int i = 0; i < data.length; i++){
- System.out.print(data[i]+" ");
- }
- System.out.print("\nMasukkan angka berapa yang ingin kamu cari : ");
- int key = in.nextInt();
- int result = index(data, key);
- if (result == -1)
- System.out.println("Angka tidak ditemukan");
- else
- System.out.println("Angka "+key+" ditemukan di index ke-"+index(data, key));
- }
- }
Add Comment
Please, Sign In to add comment