00:00

Nested Loop Examples and Exercises in Java Programming

Learn about nested loops in Java programming through provided examples and exercises. Understand the concept of nested loops and how they can be used to create patterns and iterate through multiple sets of data effectively. Practice with different scenarios and enhance your skills in handling nested loops for various programming tasks.

queirolo
Download Presentation

Nested Loop Examples and Exercises in Java Programming

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.  perulangan bersarang adalah apabila pada blok statement perulangan terdapat perulangan lagi. jadi perulangannya bisa 2 atau lebih.

  2. For i=1 to 3 do { For j=1 to 3 do { Statement; } }  1,1 1,2 1,3  2,1 2,2 2,3  3,1 3,2 3,3

  3.  Contoh FOR For (i=1:i<=5:i++) { Statement-1; For (j=1:j<=5:j++) { Statement-2; } }  Contoh While While (i<=5) { Statement-1; While (j<=5) { Statement-2; j++; } i++; }

  4. //Nama program: Nestedloop.java public class perulanganbersarang { public static void main(String[] args) { int bilangan1; int bilangan2; for (bilangan1=1; bilangan1<=3; bilangan1++) { for (bilangan2=1; bilangan2<=2; bilangan2++) { System.out.println("[" + bilangan1 + "]" + "[" + bilangan2 + "]"); } } } }

  5. package WILDAN_TECHNO_ART; import java.util.Scanner; public class latihan_java { public static void main(String[] args){ //Me [1][1] [1][2] [2][1] [2][2] [3][1] [3][2]

  6. package WILDAN_TECHNO_ART; import java.util.Scanner; public class latihan_java { public static void main(String[] args) { //Membuat Instance Scanner Scanner input = new Scanner(System.in); System.out.print("Masukan Jumlah Baris: "); int j_baris = input.nextInt(); //Menentukan Jumlah Baris //Menghitung Jumlah Baris (Outer for) for(int baris=1; baris<=j_baris; baris++) { //Mencetak Simbol * (Inner for) for(int s=1; s<=baris; s++) { System.out.print("* "); } //Membuat Baris Baru System.out.println(); } } }

  7. * ** *** **** ***** ****** *******

  8.  BUAT PROGRAM DGN OUTPUT SBB, GUNAKAN NESTED LOOP A AB ABC ABCD ABCDE

  9.  BUAT PROGRAM DGN OUTPUT SBB, GUNAKAN NESTED LOOP 1,1 1,2 1,3 2,1 2,2 2,3 3,1 3,2 3,3

More Related