1. penulisan array yang benar adalah : double[] mylist; mylist = new double[10]; array with mylist...

25
REVIEW ALGORITMA DAN MOOP

Upload: randy-alleyne

Post on 13-Dec-2015

217 views

Category:

Documents


0 download

TRANSCRIPT

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

REVIEW ALGORITMA DAN MOOP

Page 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

ARRAY1. 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.

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

2D ARRAY

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

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);

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

ARRAY STRING

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]);

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

ADVANCED ARRAYEasy to duplicate easy

int[] sourceArray = new int[10];int[] targetArray = new int[sourceArray.length];

Easy to loopingfor( int i = 0 ; i < sourceArray.length ; i++ )

targetArray[i] = sourceArray[i];

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

IMPLEMENTATION

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

BREAK

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++

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

Bina Nusantara

BREAK

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

CONTINUE

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 loopingFollowing statement be ignoredValue j==2 (following statement) not printed in j++Value j==3 (following statement) printed

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

CONTINUE

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

EXCEPTION HANDLING

Bina Nusantara

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

EXCEPTION HANDLING 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

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

METHOD

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)

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

METHOD OVERLOADING

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

FACTORIAL

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

PALINDROM

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

BUBBLE SORT ASCENDING

Bina Nusantara

Bubble Sort

• Adjacent value compared• If increasing, then change to become decreasing

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

BUBBLE SORT WITH FLAG

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

SELECTION SORT

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

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

RANDOM NUMBER Import Declaration

import java.util.Random;

Random InitializationRandom r = new Random();

Using of random numberint 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.

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

IMPLEMENTATION

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

CURRENCY FORMAT

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

PAUSING EXECUTION pausing execution for certain time Useful for simple animation Syntax:

try{

Thread.sleep(milliseconds);}catch(Exception e){}

1 second = 1000 milliseconds

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

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