Created
August 17, 2017 12:53
-
-
Save chez14/f0c2d2d7f0c0a7db5e91e84c37cb35fd to your computer and use it in GitHub Desktop.
Mana yang paling cepat?
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
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