Created
October 4, 2017 12:57
-
-
Save sugiartocokrowibowo/552340f23d6ff8682ff1447e0c76a726 to your computer and use it in GitHub Desktop.
This file contains hidden or 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; | |
public class J { | |
/** | |
* @param args | |
*/ | |
public static void main(String[] args) { | |
Scanner s = new Scanner(System.in); | |
System.out.println("INPUT"); | |
System.out.print("n : "); | |
int n = s.nextInt(); | |
double[]data = new double[n]; | |
for(int i=0;i<n;i++){ | |
System.out.print("elemen ["+i+"]: "); | |
data[i]=s.nextDouble(); | |
} | |
System.out.println("bilangan yang dicari: "); | |
double c = s.nextDouble(); | |
int index = -1; | |
for(int i=0;i<n;i++){ | |
if(data[i]==c){ | |
index = i; | |
break; | |
} | |
} | |
System.out.println("\nOUTPUT"); | |
if(index==-1){ | |
System.out.println("Bilangan yang dicari tidak berada di dalam array"); | |
}else{ | |
System.out.println("Bilangan yang dicari berada di index array ke: "+index); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment