1 / 25

Review ALGORITMA dan MOOP

Review ALGORITMA dan MOOP. Array. Penulisan array yang benar adalah : double [] myList ; myList = new double [10]; Array with myList has variable dimension 10 Index begin from 0 till 9 Value at array dimension > 0 Begin from 0 till n-1

aziza
Télécharger la présentation

Review ALGORITMA dan MOOP

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Review ALGORITMAdan MOOP

  2. Array • Penulisan array yang benar adalah : double[] myList; myList = newdouble[10]; • Array with myList has variable dimension 10 • Index begin from 0 till 9 • Value at array dimension > 0 • Begin from 0 till n-1 • Value at […] be in in the form of integer variable.

  3. 2D array

  4. Array length • To know length of array can use array. length Example: Array 1 dimension: int [] bilangan = new int[10]; System.out.println(“length of array 1 dimension: "+bilangan.length);

  5. Array string • Example of array data char type: char[] city = {‘D’,’a’,’l’,’l’,’a’,’s’}; to print: System.out.println(city); • Example array for String: String[] name={"Andre", "Bunga", "Christine", "Dedianto"}; To print name index-0  System.out.println(name[0]); To print name index-1  System.out.println(name[1]);

  6. Advanced array • Easy to duplicate easy int[] sourceArray = new int[10]; int[] targetArray = new int[sourceArray.length]; • Easy to looping for( inti = 0 ; i < sourceArray.length ; i++ ) targetArray[i] = sourceArray[i];

  7. implementation

  8. BReak for(inti=1; i<=3; i++) { for(int j=1; j<=3; j++) { if(j==2) break; System.out.println("i="+i+" dan j="+j); } } • At j==2, execution exit from inner looping • Value j==2, and j==3 not printed • Looping continued at i++

  9. break

  10. continue for(inti=1; i<=3; i++) { for(int j=1; j<=3; j++) { if(j==2) continue; System.out.println("i="+i+" dan j="+j); } } • At j==2, execution not exit from looping • Following statement be ignored • Value j==2 (following statement) not printed in j++ • Value j==3 (following statement) printed

  11. continue

  12. Exception handling

  13. Exception handling • Statements that can cause exception are in scope try • Exception catch are in scope catch • Statement that in scopecatch is a operation that done if exception occurred • Exception catch at catch Exception e) • After catch, then program will be back to normal. • The next Statement will be running normal

  14. Method Declaration Method formal parameter return value modifier method name public static int max(int num1, int num2) { int result; if(num1>num2) result = num1; else result = num2; return result; } int z = max(x, y); method header parameter list method body return value Calling of method actual parameters (arguments) Bina Nusantara

  15. Method overloading

  16. factorial

  17. palindrom

  18. Bubble Sort Bubble sort ascending • Adjacent value compared • If increasing, then change to become decreasing Bina Nusantara

  19. Bubble sort with flag

  20. Selection sort • Search for the biggest value put at the end of array

  21. Random number • Import Declaration import java.util.Random; • Random Initialization Random r = new Random(); • Using of random number inti = r.nextInt(int n)  int >= 0 and < n. inti = r.nextInt() int (full range). long l = r.nextLong()  long (full range). float f = r.nextFloat()  float >=0.0 dan < 1.0. boolean b = r.nextBoolean() boolean (trueataufalse). double d = r.nextGaussian()  double mean 0.0 danstandardeviasi 1.0.

  22. implementation

  23. Currency format

  24. Pausing execution • pausing execution for certain time • Useful for simple animation • Syntax: try { Thread.sleep(milliseconds); } catch(Exception e) { } • 1 second = 1000 milliseconds

  25. preparation • For multiple choice, read theories and examples from BINUSMAYA • For essay, Please try to make programs for : - 2 dimension array and read data for arrays • Declaring method and calling it • Bubble and selection sort

More Related