Pages

Ads 468x60px

Sharing Ilmu Pengetahuan

Switch Case Array

import java.io.*;
public class swcs_array {

    public static void main(String[]args)throws IOException
    {
       
        double harga[]=new double[4];
        double tot[]=new double[4];
        int angka[]=new int[4];
        int kode[]=new int[4];
        int jmh[]=new int[4];
       
        int i;
        for(i=1;i<4;i++)
        {
        BufferedReader br;
        br=new BufferedReader(new InputStreamReader(System.in));
        angka[i]=i;
        System.out.println("Daftar Barang ke "+angka[i]);
        System.out.println("========================================");
        System.out.print("Masukkan Kode   : ");
        kode[i] = Integer.parseInt(br.readLine());
        System.out.print("Masukkan Jumlah : ");
        jmh[i] = Integer.parseInt(br.readLine());
       
        switch (kode[i])
        {
        case 1:    harga[i]=2000;
                tot[i]= jmh[i]*harga[i];
                System.out.println("Buku");
                System.out.println("Harga = "+harga[i]);
                System.out.println("Total = "+tot[i]);
                break;
               
        case 2: harga[i]=3000;
                tot[i]= jmh[i]*harga[i];
                System.out.println("Pensil");
                System.out.println("Harga = "+harga[i]);
                System.out.println("Total = "+tot[i]);
                break;

        case 3: harga[i]=3500;
                tot[i]= jmh[i]*harga[i];
                System.out.println("Bolpoint");
                System.out.println("Harga = "+harga[i]);
                System.out.println("Total = "+tot[i]);
                break;
                 
        default: System.out.println("Invalid code.");
                 break;
        }
        }
    }
   
   
}

No comments:

Post a Comment

Your comments are very valuable

 

Sample text

Sample Text

Sample Text