$ 0 0 Pengulangan Tak Terbatas/* * Pengulangan Tak Terbatas * by : maribelajar.web.id, 2014 */ import java.io.*; public class Barang1{ public static void main(String[] args){ String Kode_Brg="", Nama_Brg=""; int Satuan=0, Harga=0; BufferedReader objInput = new BufferedReader(new InputStreamReader(System.in));+ try{ System.out.println("=================================================="); System.out.println("Welda Aprilia (1111502629)"); System.out.println("=================================================="); System.out.println("\t\tInput Data Barang "); System.out.println("=================================================="); int i=1; while (i>0){ System.out.print("Kode Barang Ke-"+i+"\t: "); Kode_Brg=objInput.readLine(); System.out.print("Nama Barang\t\t: "); Nama_Brg=objInput.readLine(); System.out.print("Satuan\t\t\t: "); Satuan=Integer.parseInt(objInput.readLine()); System.out.print("Harga\t\t\t: "); Harga=Integer.parseInt(objInput.readLine()); System.out.println("==================================================\n\n"); System.out.println("Mau Input Lagi [y/t]:"); lagi=objInput.readLine(); if (lagi.toUpperCase().equal("Y")); continue; else break; i++; } } catch(Exception e){ System.out.println("Error : "+e); } } } /* * Pengulangan Tak Terbatas * by : maribelajar.web.id, 2014 */ import java.io.*; public class Barang6{ public static void main(String[] args){ String Kode_Brg="", Nama_Brg="", lagi=""; int Satuan=0, Harga=0; BufferedReader objInput = new BufferedReader(new InputStreamReader(System.in));+ try{ System.out.println("=================================================="); System.out.println("Welda Aprilia (1111502629)"); System.out.println("=================================================="); System.out.println("\t\tInput Data Barang "); System.out.println("=================================================="); while (true){ System.out.print("Kode Barang Ke-"+i+"\t: "); Kode_Brg=objInput.readLine(); System.out.print("Nama Barang\t\t: "); Nama_Brg=objInput.readLine(); System.out.print("Satuan\t\t\t: "); Satuan=Integer.parseInt(objInput.readLine()); System.out.print("Harga\t\t\t: "); Harga=Integer.parseInt(objInput.readLine()); System.out.println("==================================================\n\n"); System.out.println("Mau Input Lagi [y/t]:"); lagi=objInput.readLine(); if (lagi.toUpperCase().equal("Y")); continue; else break; } } catch(Exception e){ System.out.println("Error : "+e); } } } Pengulangan sampai 5 kali/* * Pengulangan Sampai 5 kali * by : maribelajar.web.id, 2014 */ import java.io.*; public class Barang2{ public static void main(String[] args){ String Kode_Brg="", Nama_Brg=""; byte Satuan=0, Harga=0; BufferedReader objInput = new BufferedReader(new InputStreamReader(System.in)); try{ System.out.println("=================================================="); System.out.println("Welda Aprilia (1111502629)"); System.out.println("================================================="); System.out.println("\t\tInput Data Barang "); System.out.println("================================================="); for (int i=1; i<=5; i++){ System.out.print("Kode Barang Ke-"+i+"\t : "); Kode_Brg=objInput.readLine(); System.out.print("Nama Barang\t\t : "); Nama_Brg=objInput.readLine(); System.out.print("Satuan\t\t : "); Satuan=Byte.parseByte(objInput.readLine()); System.out.print("Harga\t\t : "); Harga=Byte.parseByte(objInput.readLine()); System.out.println("=================================================\n\n"); } } catch(Exception e){ System.out.println("Error : "+e); } } } Pengulangan Berhenti Jika Kode Barang Diisi Dengan "x"/* * Pengulangan Berhenti Jika Kode Barang Diisi Dengan "x" * by : maribelajar.web.id, 2014 */ import java.io.*; public class Barang3{ public static void main(String[] args){ String Kode_Brg="", Nama_Brg=""; int Satuan=0, Harga=0, Jumlah=0; BufferedReader objInput = new BufferedReader(new InputStreamReader(System.in)); try{ System.out.println("=================================================="); System.out.println("Welda Aprilia (1111502629)"); System.out.println("=================================================="); System.out.println("\t\tInput Data Barang "); System.out.println("=================================================="); System.out.print("Jumlah Data\t\t: "); Jumlah=Integer.parseInt(objInput.readLine()); int i=1; while (i<=Jumlah){ System.out.print("Kode Barang Ke-"+i+"\t: "); Kode_Brg=objInput.readLine(); if (Kode_Brg.equals("x")){ break;} System.out.print("Nama Barang\t\t: "); Nama_Brg=objInput.readLine(); System.out.print("Satuan\t\t\t: "); Satuan=Integer.parseInt(objInput.readLine()); System.out.print("Harga\t\t\t: "); Harga=Integer.parseInt(objInput.readLine()); System.out.println("==================================================\n\n"); i++; } } catch(Exception e){ System.out.println("Error : "+e); } } } Continue Saat Pengulangan Ke 10,20, dan 30 dan Berhenti Saat Pengulangan Ke 35 Menggunakan Struktur While/* * Continue Saat Pengulangan Ke 10,20, dan 30 dan Berhenti Saat Pengulangan Ke 35 Menggunakan Struktur While * by : maribelajar.web.id, 2014 */ import java.io.*; public class Barang4{ public static void main(String[] args){ String Kode_Brg="", Nama_Brg=""; int Satuan=0, Harga=0, k=0; BufferedReader objInput = new BufferedReader(new InputStreamReader(System.in)); try{ System.out.println("=================================================="); System.out.println("Welda Aprilia (1111502629)"); System.out.println("=================================================="); System.out.println("\t\tInput Data Barang "); System.out.println("=================================================="); int i=1; while (i>=1){ k++; if(k==10||k==20||k==30) continue; else if(k==35) break; System.out.print("Kode Barang Ke-"+k+"\t: "); Kode_Brg=objInput.readLine(); System.out.print("Nama Barang\t\t: "); Nama_Brg=objInput.readLine(); System.out.print("Satuan\t\t\t: "); Satuan=Integer.parseInt(objInput.readLine()); System.out.print("Harga\t\t\t: "); Harga=Integer.parseInt(objInput.readLine()); System.out.println("==================================================\n\n"); } } catch(Exception e){ System.out.println("Error : "+e); } } } Berhenti Sebelum Jumlah Pengulangan Berakhir Jika Menginput "x" Pada Nama Barang/* * Berhenti Sebelum Jumlah Pengulangan Berakhir Jika Menginput "x" Pada Nama Barang * by : maribelajar.web.id, 2014 */ import java.io.*; public class Barang5{ public static void main(String[] args){ String Kode_Brg="", Nama_Brg=""; int Satuan=0, Harga=0, Jumlah=0; BufferedReader objInput = new BufferedReader(new InputStreamReader(System.in)); try{ System.out.println("=================================================="); System.out.println("Welda Aprilia (1111502629)"); System.out.println("=================================================="); System.out.println("\t\tInput Data Barang "); System.out.println("=================================================="); System.out.print("Jumlah Data\t\t: "); Jumlah=Integer.parseInt(objInput.readLine()); int i=1; while (i<=Jumlah){ System.out.print("Kode Barang Ke-"+i+"\t: "); Kode_Brg=objInput.readLine(); System.out.print("Nama Barang\t\t: "); Nama_Brg=objInput.readLine(); if (Nama_Brg.equals("x")){ break;} System.out.print("Satuan\t\t\t: "); Satuan=Integer.parseInt(objInput.readLine()); System.out.print("Harga\t\t\t: "); Harga=Integer.parseInt(objInput.readLine()); System.out.println("==================================================\n\n"); i++; } } catch(Exception e){ System.out.println("Error : "+e); } } } k++; if(k==10||k==20||k==30) continue; else if(k==35) break; System.out.print("Kode Barang Ke-"+k+"\t: "); Kode_Brg=objInput.readLine(); System.out.print("Nama Barang\t\t: "); Nama_Brg=objInput.readLine(); System.out.print("Satuan\t\t\t: "); Satuan=Integer.parseInt(objInput.readLine()); System.out.print("Harga\t\t\t: "); Harga=Integer.parseInt(objInput.readLine()); System.out.println("==================================================\n\n"); } } catch(Exception e){ System.out.println("Error : "+e); } } }