mencoba menyederhanakan JAVA KUIS 24/11/2010
dengan menggunakan perulangan "FOR"
metode input : scanner
source code::
import java.util.Scanner;
public class java_for {
public static void main(String[]args){
int totalharga;
int [] nilai = new int [3];
int [] harga = new int [3];
int [] total = new int [3];
String [] nilaiStr = new String [3];
String [] hargaStr = new String [3];
String [] nama = new String [3];
Scanner input = new Scanner(System.in);
for(int x=0;x<3;x++){
System.out.print("\nitem "+(x+1)+" = ");
nama[x]=input.next();
System.out.print("banyak = ");
nilaiStr[x]=input.next();
nilai[x]=Integer.parseInt(nilaiStr[x]);
System.out.print("harga = ");
hargaStr[x]=input.next();
harga[x]=Integer.parseInt(hargaStr[x]);
total[x]=nilai[x]*harga[x];
}
totalharga=total[0]+total[1]+total[2];
System.out.println("\nbarang yang dibeli = "+(nama[0])+", "+(nama[1])+", "+(nama[2]));
System.out.println("masing masing = "+(nilai[0])+", "+(nilai[1])+", "+(nilai[2]));
System.out.println("total jumlah barang = "+totalharga);
}
}
0 komentar:
Posting Komentar