本文目录一览:
- 1、Java上机作业 声明一个字符串的数组 空间为5个 使用循环接收五个学生的
- 2、Java上机作业
- 3、1、编写一个Application程序【java上机作业,要完整代码,急求!!!!!!!!!!】
Java上机作业 声明一个字符串的数组 空间为5个 使用循环接收五个学生的
String[] arr=new String[5];
Scanner sca=new Scanner(System.in);
String name=null;
for(int i=0;iarr.lenth();i++){
System.out.print("请输入第"+(i+1)+"个学生姓名:");
name=sca.next();
arr[i]=name;
}
System.out.println("现有以下学生");
for(int i=0;iarr.lenth();i++){
System.out.println(arr[i]+"t");
}
Java上机作业
1,写一个HelloWorld
2,10秒钟内把主函数敲出来。
3,睡一觉,明天还有课
1、编写一个Application程序【java上机作业,要完整代码,急求!!!!!!!!!!】
第一题:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
public class RadioTest extends JFrame{
private JRadioButton jrb1;
private JRadioButton jrb2;
private JLabel jlbl;
private JPanel jp;
private JButton jbtn;
private String jlstr;
private ButtonGroup bg;
public RadioTest(){
jlstr = "你选择的是:";
this.setTitle("实现单选按钮的效果");
jrb1 = new JRadioButton("男");
jrb2 = new JRadioButton("女");
bg = new ButtonGroup();
bg.add(jrb1);
bg.add(jrb2);
jlbl = new JLabel(jlstr);
jbtn = new JButton("退出");
jbtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
System.exit(1);
}
});
jrb1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==jrb1){
jlbl.setText(jlstr+jrb1.getText());
}
}
});
jrb2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==jrb2){
jlbl.setText(jlstr+jrb2.getText());
}
}
});
jp = new JPanel();
jp.add(jrb1);
jp.add(jrb2);
jp.add(jlbl);
jp.add(jbtn);
this.add(jp);
this.setBounds(300, 300, 230, 200);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
RadioTest rt = new RadioTest();
}
}