Cari Blog Ini

Rabu, 08 Juni 2011

menu....

Posted by wahyu@net on 19.52

membuat menu....



import java.util.Scanner;

public class menu {
    public static void main(String[]args){
    Scanner input=new Scanner (System.in);
    int pil;
    garis();
    System.out.println("          Menu latihan");
    garis();
    System.out.println("1.menghitung rata");
    System.out.println("2.menghitung bilangan kelipatan 4");
    System.out.println("3.exit");
    garis();
    System.out.print("anda pilih nomor  =");pil=input.nextInt();
    switch(pil)
    {
        case 1:
        {
            int[] data=new int[15];
            int jumlah=0;
            System.out.print("anda pilih nomor =");int n=input.nextInt();
            for(int i=1;i<=n;i++)
        {
                System.out.print("data ke "+i+"= ");data[1]=input.nextInt();
                jumlah =jumlah+data[1];
        }
            System.out.print("jumlah="+jumlah);
            System.out.print("rata-rata="+(jumlah/n));

    break;
        }
    case 2:
        {
            int a,k;
            System.out.print("nalai awal        =");a=input.nextInt();
            System.out.print("nilai akhr        =");k=input.nextInt();
            for(int i=a;i<=k;i++)
                if(i%a ==0)
                {
                    System.out.print(i+". ");
                 }
            break;
                }
    default:System.exit(0);
    }
    }
       static void garis(){
       System.out.println("====================================");
    }

    }


out putnya..

0 komentar:

Posting Komentar

  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin

Search Site

 
  • Blogroll

  • Consectetuer

  • Popular

  • Comments