从键盘输入一个年份,判断是不是闰年.大虾帮忙写写这个程序啊!

解决方案 »

  1.   

    import javax.swing.*;
    import java.awt.Graphics;public class yearJudge extends JApplet{
    String year;
    int y;
    String judge;

    public void init(){

    year = JOptionPane.showInputDialog("Enter the year please!");
    y = java.lang.Integer.parseInt(year);
    if (y % 4==0) {

      judge = "Yes";}
    }
    public void paint (Graphics g){
    g.drawLine(15,10,210,10);
    g.drawLine(15,30,210,30);
    g.drawString(judge,25,25);
    }
    }
      

  2.   

    应该这样判断吧:
    if(
    ( (y%4==0)&&(y%100!=0) )
    ||(y%400==0)
    )
    judge="Yes";
      

  3.   

    public class Year
    {
    public boolean isLeapYear(int value)
    {
    boolean result = false;
    if((value%4 == 0 && value%100 != 0) || value%400 == 0)
    result = true;
    return result;
    }
    }
      

  4.   

    public static boolean isLeapYear(int nYear)
        {
            boolean bRet = false;
            if (0 == (nYear % 100))
            {
                if (0 == (nYear % 400))
                {
                    bRet = true;
                }
            }
            else
            {
                if (0 == (nYear % 4))
                {
                    bRet = true;
                }
            }
            return bRet;
        }