bu ninik cute tak datang, kuis pun tetap menghadang . . .
waw??? kuis input dinamis dasar, kereennn
gue pake metode input scanner neh . .
source code ::
import java.util.Scanner;
public class Quis3_4167 {
public static void main(String[]args){
int nilai1,nilai2,nilai3,totalharga;
int harga1,harga2,harga3;
int total1,total2,total3;
String nilaiStr1,nilaiStr2,nilaiStr3;
String hargaStr1,hargaStr2,hargaStr3;
String nama1,nama2,nama3;
Scanner input = new Scanner(System.in);
System.out.print("\nnama barang 1 = ");
nama1=input.next();
System.out.print("banyak = ");
nilaiStr1=input.next();
nilai1=Integer.parseInt(nilaiStr1);
System.out.print("harga = ");
hargaStr1=input.next();
harga1=Integer.parseInt(hargaStr1);
System.out.print("\nnama barang 2 = ");
nama2=input.next();
System.out.print("banyak = ");
nilaiStr2=input.next();
nilai2=Integer.parseInt(nilaiStr2);
System.out.print("harga = ");
hargaStr2=input.next();
harga2=Integer.parseInt(hargaStr2);
System.out.print("\nnama barang 3 = ");
nama3=input.next();
System.out.print("banyak = ");
nilaiStr3=input.next();
nilai3=Integer.parseInt(nilaiStr3);
System.out.print("harga = ");
hargaStr3=input.next();
harga3=Integer.parseInt(hargaStr3);
total1=nilai1*harga1;
total2=nilai2*harga2;
total3=nilai3*harga3;
totalharga=total1+total2+total3;
System.out.println("barang yang dibeli = "+nama1+", "+nama2+", "+nama3);
System.out.println("masing masing = "+nilai1+", "+nilai2+", "+nilai3);
System.out.println("total jumlah barang = "+totalharga);
}
}
0 komentar:
Posting Komentar