Minggu, 14 April 2013

Penentu Jumlah Hari

Nikmati nih broo...
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package JumlahHari;

import java.util.Scanner;

/**
 *
 * @author Khoiril
 */
public class JumlahHari {
    public static void main(String[]args){
        Scanner input = new Scanner(System.in);
        System.out.print("Masukkan Tahun  :");
        int tahun;
        tahun = input.nextInt();
        System.out.print("Masukkan Bulan  :");
        int bulan;
        bulan = input.nextInt();
        int hari;
        switch (bulan){
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                hari = 31; System.out.println("Jumlah Hari Pada Tahun "+tahun+" bulan "+bulan+" adalah "+hari+" hari");
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                hari = 30; System.out.println("Jumlah Hari Pada Tahun "+tahun+" bulan "+bulan+" adalah "+hari+" hari");
                break;
            case 2:
                if (((tahun % 4 == 0) && !(tahun % 100 == 0))|| (tahun % 400 == 0)) {
            hari = 29; System.out.println("Jumlah Hari Pada Tahun "+tahun+" bulan "+bulan+" adalah "+hari+" hari");
        }
                                else {
            hari = 28; System.out.println("Jumlah Hari Pada Tahun "+tahun+" bulan "+bulan+" adalah "+hari+" hari");
        }
                break;
            default:
                System.out.println("Pilihan Salah!");
                break;
                   
        }
    }
}
Share:

0 komentar:

Posting Komentar

Diberdayakan oleh Blogger.

Archive

Labels

My Motto

Labels

Blogger templates