Pada pembahasan kali ini saya akan mempublikasikan program java menggunakan array.
//RAHMAN ADI FIRMANSYAH
package javaapplication16;
import java.util.Scanner;
public class arrray {
public static void main(String[] args) {
Scanner van = new Scanner(System.in);
int brg;
System.out.print("Input Barang = ");
brg = van.nextInt();
String nama[] = new String[brg];
int hrg[] = new int[brg];
int jml[] = new int[brg];
int ttl[] = new int[brg];
int ttl1 = 0;
for (int a = 0; a < brg; a++){
System.out.print("Nama Barang : ");
nama[a] = van.next();
System.out.print("Harganya : ");
hrg[a] = van.nextInt();
System.out.print("Jumlahnya : ");
jml[a] = van.nextInt();
ttl[a] = hrg[a]*jml[a];
System.out.println("Total Bayar = "+ttl[a]);
System.out.println(" ");
ttl1=ttl1+ttl[a];
}
System.out.println(" ");
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.println("| Nama Barang\t\t| Barang | Harga\t| Total\t\t|");
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
for (int c = 0; c < brg; c++){
System.out.println("| "+nama[c]+"\t\t\t| "+jml[c]+"\t | Rp."+hrg[c]+"\t| Rp."+jml[c]*hrg[c]+"\t|");
}
System.out.println("Total Belanjaan = Rp." +ttl1);
}
}
Tidak ada komentar:
Posting Komentar