Pemrograman berorientasi objek
Download
1 / 31

PEMROGRAMAN BERORIENTASI OBJEK - PowerPoint PPT Presentation


  • 153 Views
  • Uploaded on

PEMROGRAMAN BERORIENTASI OBJEK. Kondisional Perulangan Percabangan. Struktur Kontrol. 1. Kondisional. Pernyataan if Pernyataan if – else Pernyataan if – else if Pernyataan switch. 2. Kondisional.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' PEMROGRAMAN BERORIENTASI OBJEK' - cate


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Pemrograman berorientasi objek

PEMROGRAMAN BERORIENTASI OBJEK

  • Kondisional

  • Perulangan

  • Percabangan

StrukturKontrol


1 kondisional
1. Kondisional

  • Pernyataan if

  • Pernyataan if – else

  • Pernyataan if – else if

  • Pernyataan switch


2 kondisional
2. Kondisional

Pernyataan kondisional memanfaatkan ekspresi boolean yang dapatberupa true atau false (sehinggadisebutbinary decision). Aksi yang dikerjakantergantungpadanilaihasildariekspresi:


Pernyataan if
Pernyataan if

  • Pernyataan if menentukansebuah statement yang akandieksekusijikadanhanyajikapersyaratanboolean (boolean statement) bernilai true. Bentukumum :

    if( boolean_expression )

    statement;

    Atau

    if( boolean_expression ){

    statement1;

    statement2;

    . . .

    }


Flowchart pernyataan if
Flowchart Pernyataan if


Pernyataan if else
Pernyataan if - else

Pernyataan if-else digunakanapabilakitainginmengeksekusisebuah statement dengankondisitrue dan statement yang lain dengankondisi false.

Bentukumum :

if( boolean_expression ) atau if(boolean_expression)

statement; {

else statement1;

statement; statement2;

} else{

statement;

… ;

}


Flowchart pernyataan if else
Flowchart Pernyataan if-else


Contoh
Contoh :

public class coba {

public static void main(String[]args)

{

int grade = 68;

if( grade > 60 ){

System.out.println(“selamat!");

System.out.println(“kamu lulus!");

}

else{

System.out.println(“maaf, kamutidak lulus");

}

}

}


Pernyataan if else if
Pernyataan if-else if

Bentukumum :

if( boolean_expression1 )

statement1;

else if( boolean_expression2 )

statement2;

else

statement3;



Pernyataan switch
Pernyataan switch

switch( switch_expression ){

case case_selector1:

statement1; //

statement2; //block 1

. . . //

break;

case case_selector2:

statement1; //

statement2; //block 2

. . . //

break;

. . .

default:

statement1; //

statement2; //block n

. . . //

break;

}



Contoh1
Contoh :

public class coba {

public static void main(String[]args)

{

int grade = 80;

switch(grade){

case 100:

System.out.println( "Excellent!" );

break;

case 90:

System.out.println("Good job!" );

break;

case 80:

System.out.println("Study harder!" );

break;

default:

System.out.println("Sorry, you failed.");

}}}


2 perulangan
2. Perulangan

  • Pernyataan while

  • Pernyataan do..while

  • Pernyataan for


Pernyataan while
Pernyataan while

  • Pernyataan while akandijalankansecaraterus-menerusselamakondisibernilaibenar(true).

  • Bentukumum :

    while( boolean_expression )

    {

    statement1;

    statement2;

    . . .

    }


Contoh2
Contoh :

public class coba {

public static void main(String[]args)

{

inti = 4;

while ( i > 0 ){

System.out.print(i);

i--;

}

}

}


Pernyataan do while
Pernyataan do..while

  • Pernyataan do..while, statement dieksekusisetidaknyasatu kali.

  • Bentukumum :

    do{

    statement1;

    statement2;

    . . .

    }while( boolean_expression );


Contoh3
Contoh :

public class coba {

public static void main(String[]args)

{

int x = 0;

do

{

System.out.print(x);

x++;

}while (x>10);

}

}


Pernyataan for
Pernyataan for

  • Pernyataan for , melakukaneksekusipengulanganbeberapa kali.

  • Bentukumum :

    for (Initialization; LoopCondition; StepExpression){

    statement1;

    statement2;

    . . .

    }

    Initialization – inisialisasi dari variabel loop.

    LoopCondition - membandingkanvariabel loop

    padanilaibatas.

    StepExpression - melakukan update pada

    variabel loop.


Contoh4
Contoh :

public class coba {

public static void main(String[]args)

{

inti;

for( i = 0; i < 10; i++ ){

System.out.print(i);

}

}

}


Percabangan
Percabangan

  • Pernyataan break

  • Pernyataan continue


Pernyataan break
Pernyataan break

  • Pernyataan break digunakan utk menghentikan jalannya statement.

  • Pernyataan break ada 2 :

    - unlabeled break

    - labeled break


Unlabeled break
Unlabeled break

while(…){

while (…) {

if (…)

break;

} //akhir while terdalam

pernyataansesudah while

….

} //akhir while terluar


Contoh5
Contoh :

public class cabang {

public static void main(String[]args)

{

int i=0, j=0;

while (i<3){

j=0;

while(j<5){

if (j==3)

break;

System.out.println("i = " + i +" j = "+ j);

j++;

}

i++;

}

}}



Labeled break
Labeled break

selesai :

while(…){

while (…) {

if (…)

break selesai;

} //akhir while terdalam

pernyataansesudah while

….

} //akhir while terluar

Pernyataan_x;

Label


Contoh6
Contoh

System.out.println("i = " + i +" j = "+ j);

j++;

}

i++;

}

System.out.println("Akhir program");

}

}

public class cabang {

public static void main(String[]args)

{

int i=0, j=0;

selesai:

while (i<3){

j=0;

while(j<5){

if (j==3)

break selesai;



Pernyataan continue
Pernyataan continue

  • Pernyataancontunieberfungsiutkmengarahkaneksekusikekondisipernyataanperulanganshgkondisiakandievaluasilagi.


Contoh8
Contoh :

public class cabang {

public static void main(String[]args)

{

inti=0;

while(i<5){

if (i==3){

i++;

continue;

}

System.out.println(i);

i++;

}

}

}


Tugas
Tugas

  • Buat flowchart dan program utk- kondisional (if, if-else, switch)

    - perulangan (while, do.. while, for)

    - percabangan(break, continue)


ad