Skip to content

Instantly share code, notes, and snippets.

@chez14
Created August 17, 2017 12:53
Show Gist options
  • Save chez14/f0c2d2d7f0c0a7db5e91e84c37cb35fd to your computer and use it in GitHub Desktop.
Save chez14/f0c2d2d7f0c0a7db5e91e84c37cb35fd to your computer and use it in GitHub Desktop.
Mana yang paling cepat?
public class Kambing {
public static void main(String[] args){
int[] hive = {1,2,3,4,5,6,7,8,9,0};
int needle = 8;
/*
Ada 3 buah method yang bisa digunakan, dan sama-sama jalan semua.
tapi mana yang lebih cepet dari 3-3nya ini?
- cariAngka1
- cariAngka2
- cariAngka3
*/
}
public static boolean cariAngka1(int[] hive, int needle){
for(int i=0; i<hive.length; i++){
if(hive[i] == needle){
return true;
}
}
return false;
}
public static boolean cariAngka2(int[] hive, int needle){
boolean result=false;
for(int i=0; i<hive.length; i++){
if(hive[i] == needle) {
result = true;
}
}
return result;
}
public static boolean cariAngka3(int[] hive, int needle){
for(int h:hive){
if(h == needle){
return true;
}
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment