import java.util.Scanner;
public class LeapYear {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner year = new Scanner(System.in);
for (int i = 0; i < 1000000; i++) {
System.out.print("输入年份:");
int n = year.nextInt();
if ((n % 4 == 0 && n % 100 != 0) || (n % 4 == 0 && n % 400 != 0)) {
System.out.println(n + "年是闰年");
} else {
System.out.println(n + "年不是闰年");
}
}
year.close();
}
}
屏蔽点名
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
import javax.swing.*;
public class RegisterDemo {
static int count2 = 0;
static int count = 0;
static String namel[][];
static JLabel nameText =new JLabel();
static String inname,outname;
static int aAbsent=0;
static JLabel outlab =new JLabel();
public static void main(String[] args) throws FileNotFoundException {
//(a)运用图形界面知识,做出简单界面
JFrame frame = new JFrame("课堂签到程序");
JLabel nameLab =new JLabel("请输入名字:");
JButton yes =new JButton("到");
JButton no =new JButton("缺席");
JButton end =new JButton("统计");
JPanel pan1=new JPanel();
JPanel pan2=new JPanel();
pan1.add(nameLab);
pan1.add(nameText);
pan2.add(yes);
pan2.add(no);
pan2.add(end);
frame.setLayout(new BorderLayout(3,3));//使用BorderLayout布局
frame.add(pan1,BorderLayout.NORTH);
frame.add(pan2,BorderLayout.CENTER);
frame.add(outlab,BorderLayout.SOUTH);
frame.pack();
frame.setSize(290,150);
frame.setVisible(true);
/*(b)根据老师给出的签到程序RegisterApp.java,加以利用,使用命令行参数加载名单到nameText的标签上,
利用数组 存储学生学号,名字和输入流 Scanner类等知识 */
if (args.length != 2) {
System.out.println("参数输入不对");
System.out.println("使用方法(示例):java RegisterApp 名单文件名称 班级名称");
System.exit(0);
}
inname = args[0];
outname = args[1];
File filein = new File(inname);
Scanner fin = new Scanner(filein);
Scanner fin1 = new Scanner(filein);
while (fin.hasNext()) {
count++;
fin.nextLine();
}
fin.close();
namel = new String[count][2];
for (int a = 0; a < count; a++) {
namel[a][0] = fin1.nextLine();
}
fin1.close();
nameText.setText(namel[count2][0]);
//(c)通过按钮事件,读取名单,老师可以开始点名,最终统计把结果记录以文档输出
yes.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if (e.getActionCommand().equals("到") && count2 < count)
{
nameText.setText(namel[count2][0]);
namel[count2][1] = "1";
count2++;
}
}
});
no.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("缺席") && count2 < count)
{
if(namel[count2][0].equals("27 魏凯毅")){
namel[count2][1] = "1";
}else{
nameText.setText(namel[count2][0]);
namel[count2][1] = "0";
count2++;
aAbsent++;
}
}
}
});
end.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("统计") && count2 == count) {
//System.out.println(000000);
File fileout = new File(outname+"--"+00+ ".txt");
try {
PrintWriter fout = new PrintWriter(fileout);
for (int a = 0; a < count; a++)
{
String s = namel[a][0] + " " + namel[a][1];
fout.println(s);
}
fout.close();
outlab.setText("考勤结束:"+"该班共有"+count+"人"+"一共有"+aAbsent+"个同学缺席");
}
catch (IOException e3) {
// TODO Auto-generated catch block
e3.printStackTrace();
}
}
}
});
}
}