Presentation is loading. Please wait.

Presentation is loading. Please wait.

1. Penulisan array yang benar adalah : double[] myList; myList = new double[10];  Array with myList has variable dimension 10  Index begin from 0 till.

Similar presentations


Presentation on theme: "1. Penulisan array yang benar adalah : double[] myList; myList = new double[10];  Array with myList has variable dimension 10  Index begin from 0 till."— Presentation transcript:

1

2 1. 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  Value at […] be in in the form of integer variable.

3

4  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 Bina Nusantara  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  Easy to duplicate easy int[] sourceArray = new int[10]; int[] targetArray = new int[sourceArray.length];  Easy to looping for( int i = 0 ; i < sourceArray.length ; i++ ) targetArray[i] = sourceArray[i];

7

8 Bina Nusantara for(int i=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 Bina Nusantara

10 for(int i=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

12 Bina Nusantara

13  Statements that can cause exception are in scope try  Exception catch are in scope catch  Statement that in scope catch 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 Bina Nusantara Method Declaration 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); modifier return value method name formal parameter method header parameter list method body return value Calling of method actual parameters (arguments)

15

16

17

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

19

20 Search for the biggest value put at the end of array

21  Import Declaration import java.util.Random;  Random Initialization Random r = new Random();  Using of random number int i = r.nextInt(int n)  int >= 0 and < n. int i = 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 (true atau false). double d = r.nextGaussian()  double mean 0.0 dan standar deviasi 1.0.

22

23

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

25  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


Download ppt "1. Penulisan array yang benar adalah : double[] myList; myList = new double[10];  Array with myList has variable dimension 10  Index begin from 0 till."

Similar presentations


Ads by Google