(5)阅读程序给出程序的功能
import java.io.*;
class test
{
public static void main(String args[])
{
int x,y;
if(args.length<2)
System.out.print("请输入两个命令行参数");
else if (args.length>=3)
System.out.print("命令行参数参数的个数多于两个");
else{
x=Integer.parseInt(args[0]);
y=Integer.parseInt(args[1]);
if(x>=y)
System.out.print(y);
else
System.out.print(x);
}
}
}
5、编写程序题(本题共20分)
1、编写程序实现窗口,包含一个标签、一个文本框和一个按钮,当用户单击按钮时,程序把文本框中的内容复制到标签中。(使用AWT)(根据提示在相应的位置填入正确的语句,标注(1)(2)(3)(4)的地方)。
//引入相关包
(1)
public class MyFrame implements ActionListener
{
Label lbl;
TextField txt;
Button btn;
public MyFrame()
{
Frame fr = new Frame();
//设置窗体的布局为FlowLayout
(2)
lbl = new Label("初始信息");
txt = new TextField(30);
btn = new Button("确定");
fr.add(lbl);
fr.add(txt);
fr.add(btn);
//给按钮注册监听器
(3)
//使用窗体可见,并设置大小
(4)
}
public void actionPerformed(ActionEvent e)
{
lbl.setText(txt.getText());
}
public static void main(String args[])
{
new MyFrame();
}
}
2、编写一个Application程序:判断一个数是否为素数
要求:此数据是从命令行参数得到,然后判断其是否为素数,如果是,打印“是素数”,如果不是,则打印“不是素数”,如果没有参数输入,显示“请输入一个参数” 。