java求闰年
发布时间: 2023-03-30 17:23:28
Ⅰ 用java程序判断是否是闰年
以下为代码:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class LeapyearTest extends Applet implements ActionListener{
Label lblResult;
Button btn;
TextField txt;
int year;
boolean leap;
public void init() {
lblResult=new Label("请输入要判断的年份");
txt=new TextField(5);
btn=new Button("判断");
add(lblResult);
add(txt);
add(btn);
btn.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
year=Integer.parseInt(txt.getText());
if(year%4==0&;&;(year%100)!=0)
{leap=true;
}
else if(year%400==0){
leap=false;
}
if(leap==true)
lblResult.setText(year+"年是闰年");
else
lblResult.setText(year+"年是平年");
txt.setText("");
}
}
热点内容