GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — stackJava/stackBuku.java at main · akhmdrdlo/stackJava Expand file tree/ Copy pathstackBuku.javaMore file actions 52 lines (45 loc) · 1.72 KB / Copy pathstackBuku.javaFile metadata and controls52 lines (45 loc) · 1.72 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Stack; public class stackBuku { private static Stack<String> stack; private static int batas; public static void main(String[] args) throws IOException { System.out.println("Berapa banyak buku yang ingin disimpan?"); batas = inputBuku(); buatStack(batas); taruhBuku(); lihatData(); } public static void buatStack(int batas) { stack = new Stack<String>(); } public static void taruhBuku() throws IOException { String data; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Saatnya menaruh buku!! "); for (int i = 0; i < batas; i++) { System.out.print("Buku ke-" + (i + 1) + " : "); data = br.readLine(); // Menggunakan nextLine() untuk membaca string stack.push(data); System.out.println("_______________________________"); } } private static void lihatData() { System.out.println("_______________________________"); System.out.println("Buku yang ditumpuk dari bawah ke atas : "); String dataBuku; for (int i = 0; i < batas; i++) { // Mengeluarkan elemen dari stack dataBuku = stack.pop(); System.out.println("Judul Buku = " + dataBuku); } } private static int inputBuku() throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String angkaInput = br.readLine(); int data = Integer.parseInt(angkaInput); return data; } } |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |