Rabu, 08 Juni 2011

Lat. Menu

import java.util.Scanner;
public class latihan {

    public static void main(String[] args){
        Scanner input=new Scanner(System.in);

        garis();
        System.out.println("       MENU PILIHAN");
        garis();
        System.out.println("1. MENGHITUNG NILAI RATA - RATA");
        System.out.println("");
        System.out.println("2.MENGHITUNG BILANGAN KELIPATAN 4");
        System.out.println("");
        garis();


        System.out.print("Anda pilih nomor :");int pil=input.nextInt();
        switch(pil){
        case 1 :{
            int jum=0;
            System.out.println("menghitung nilai rata-rata");
            int[]data=new int[5];
            System.out.println("jumlah data=");int n=input.nextInt();
            for(int i=1;i<=n;i++)
            {
                System.out.println("Datake "+i+"=");data[i]=input.nextInt();
                jum=jum+data[i];
            }
            System.out.println("jumlah"+jum);
            System.out.println("Rata-Rata="+(jum/n));
            break;
        }
            case 2:{
                System.out.println("mengitung bilangan kelipatan 4");
                System.out.println("dari =");int awal=input.nextInt();
                System.out.println("sampai =");int akhir=input.nextInt();
                for(int i=awal;i<=akhir;i++ )
                {
                    if(i%4==0)
                    {
                        System.out.print(i+",");

                    }
                }
                break;
            }
            default:System.exit(0);
        }
    }
static void garis (){
    System.out.println("-----------------------------------------------------");
}
}