ARRAY JAVA

Membuat suatu program dengan "Array" dan menggunakan inputan scanner pada NetBeans


package arrayjava;
import java.util.Scanner;
public class ArrayJava {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);      
System.out.print("Berapa Banyak Pembelian Anda = ");
int belanja = sc.nextInt();
String nama[] = new String[belanja];
int harga[] = new int[belanja];
int jumlah[] = new int[belanja];
int tot[] = new int[belanja];
int total=0;
for (int b = 0; b < belanja; b++){
System.out.print("Nama Barang Yang Dibeli= ");
nama[b] = sc.next();
System.out.print("Harga "+nama[b]+" Yang Dibeli = ");
harga[b] = sc.nextInt();
System.out.print("Jumlah "+nama[b]+" Yang Dibeli = ");
jumlah[b] = sc.nextInt();
tot[b] = harga[b]*jumlah[b];
System.out.println("Total Bayar = "+tot[b]);
System.out.println(" ");
total=total+tot[b];}
System.out.println("Minimarket");
System.out.println(" ");
for (int c = 0; c < belanja; c++){
System.out.println("Total Harga Barang = "+(c+1));
System.out.println("1. Nama Barang   = "+nama[c]);
System.out.println("2. Harga Barang  = "+harga[c]);
System.out.println("3. Jumlah Barang = "+jumlah[c]);}
System.out.println("");
System.out.println("Total Belanjaan Seluruhnya  = "+total);
System.out.println("Selamat Datang Kembali");
    }
}

Sekian dan terima kasih






Next PostPosting Lebih Baru Previous PostPosting Lama Beranda

0 komentar:

Posting Komentar