1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | package hisoka.poipo; import java.util.Arrays; public class MainArraySorting { public static void main(String[] args) { // TODO Auto-generated method stub int[] hisoka = {-1,8, 4,7,2,10,3,2}; displayArray(hisoka); Arrays.sort(hisoka); System.out.println("\nSetelah di sort : "); displayArray(hisoka); //ini pake binarySearch int indeks = Arrays.binarySearch(hisoka, 7); System.out.println(indeks); } public static void displayArray(int[] A) { for (int a: A) { System.out.print(a+" "); } System.out.print("\n"); } } |
Hasil :
Sooo..untuk ngesort array itu pake cara di line 11, terus klu binarySearch di line 16 ehehe.. :D
No comments:
Post a Comment