1 / 32

PEMROGRAMAN BERORIENTASI OBJEK

PEMROGRAMAN BERORIENTASI OBJEK. Oleh : Sri Herawati, S.Kom Blog : zheira83.wordpress.com. Struktur Kontrol. Manajemen Informatika Fakultas Teknik Universitas Trunojoyo Madura 2009. Sub Topik. Kondisional Perulangan Percabangan. Kondisional. Pernyataan if Pernyataan if – else

mostyn
Télécharger la présentation

PEMROGRAMAN BERORIENTASI OBJEK

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. PEMROGRAMAN BERORIENTASI OBJEK Oleh : Sri Herawati, S.Kom Blog : zheira83.wordpress.com Struktur Kontrol Manajemen Informatika Fakultas Teknik Universitas Trunojoyo Madura 2009

  2. Sub Topik • Kondisional • Perulangan • Percabangan

  3. Kondisional • Pernyataan if • Pernyataan if – else • Pernyataan if – else if • Pernyataan switch

  4. Kondisional Pernyataan kondisional memanfaatkan ekspresi boolean yang dapat berupa true atau false (sehingga disebut binary decision). Aksi yang dikerjakan tergantung pada nilai hasil dari ekspresi:

  5. Pernyataan if • Pernyataan if menentukan sebuah statement yang akan dieksekusi jika dan hanya jika persyaratan boolean (boolean statement) bernilai true. Bentuk umum : if( boolean_expression ) statement; Atau if( boolean_expression ){ statement1; statement2; . . . }

  6. Flowchart Pernyataan if

  7. Pernyataan if - else Pernyataan if-else digunakan apabila kita ingin mengeksekusi sebuah statement dengan kondisi true dan statement yang lain dengan kondisi false. Bentuk umum : if( boolean_expression ) atau if(boolean_expression) statement; { else statement1; statement; statement2; } else{ statement; … ; }

  8. Flowchart Pernyataan if-else

  9. 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, kamu tidak lulus"); } } }

  10. Pernyataan if-else if Bentuk umum : if( boolean_expression1 ) statement1; else if( boolean_expression2 ) statement2; else statement3;

  11. Flowchart pernyataan if-else if

  12. 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; }

  13. Flowchart switch

  14. 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."); }}}

  15. Perulangan • Pernyataan while • Pernyataan do..while • Pernyataan for

  16. Pernyataan while • Pernyataan while akan dijalankan secara terus-menerus selama kondisi bernilai benar(true). • Bentuk umum : while( boolean_expression ) { statement1; statement2; . . . }

  17. Contoh : public class coba { public static void main(String[]args) { int i = 4; while ( i > 0 ){ System.out.print(i); i--; } } }

  18. Pernyataan do..while • Pernyataan do..while, statement dieksekusi setidaknya satu kali. • Bentuk umum : do{ statement1; statement2; . . . }while( boolean_expression );

  19. Contoh : public class coba { public static void main(String[]args) { int x = 0; do { System.out.print(x); x++; }while (x>10); } }

  20. Pernyataan for • Pernyataan for , melakukan eksekusi pengulangan beberapa kali. • Bentuk umum : for (Initialization; LoopCondition; StepExpression){ statement1; statement2; . . . } Initialization – inisialisasi dari variabel loop. LoopCondition - membandingkan variabel loop pada nilai batas. StepExpression - melakukan update pada variabel loop.

  21. Contoh : public class coba { public static void main(String[]args) { int i; for( i = 0; i < 10; i++ ){ System.out.print(i); } } }

  22. Percabangan • Pernyataan break • Pernyataan continue

  23. Pernyataan break • Pernyataan break digunakan utk menghentikan jalannya statement. • Pernyataan break ada 2 : - unlabeled break - labeled break

  24. Unlabeled break while(…){ while (…) { if (…) break; … } //akhir while terdalam pernyataan sesudah while …. } //akhir while terluar

  25. 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++; } }}

  26. Hasil

  27. Labeled break Label selesai : while(…){ while (…) { if (…) break selesai; … } //akhir while terdalam pernyataan sesudah while …. } //akhir while terluar Pernyataan_x;

  28. Contoh : 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; System.out.println("i = " + i +" j = "+ j); j++; } i++; } System.out.println("Akhir program"); } }

  29. Contoh :

  30. Pernyataan continue • Pernyataan contunie berfungsi utk mengarahkan eksekusi ke kondisi pernyataan perulangan shg kondisi akan dievaluasi lagi.

  31. Contoh : public class cabang { public static void main(String[]args) { int i=0; while(i<5){ if (i==3){ i++; continue; } System.out.println(i); i++; } } }

  32. Tugas • Buat flowchart dan program utk - kondisional (if, if-else, switch) - perulangan (while, do.. while, for) - percabangan(break, continue) • Kelompok maks 2 orang • Dikumpulkan tgl 25 september 2009 lewat email: zheira83@yahoo.com

More Related