「分配学号java」学号是怎么安排的
本篇文章给大家谈谈分配学号java,以及学号是怎么安排的对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、用java的if语句编写个班级管理程序,用于接收姓名实例化,可以自动分配学号和班级
- 2、如何用java语言编写一个叫学号器,比如班里有五十个同学,按一下按钮,随机叫出一个同学的名字!求详细代
- 3、Java 定义一个学生类,属性包括:学号,姓名,年龄,班级和电话,设计所有变量的get set方
- 4、java 假设一个班级共35人, 学号从1~35, 请编写程序进行随机学号抽取, 每个学号不
用java的if语句编写个班级管理程序,用于接收姓名实例化,可以自动分配学号和班级
public static void main(String... args) {
// 姓名列表
String[] names = new String[]{"张1", "张2", "张3", "张4", "张5", "张6", "张7", "张8", "张9", "张10", "张11", "张12", "张13", "张14",
"张15", "张16", "张17", "张18", "张19", "张20", "张21", "张22", "张23"};
MapString, ListJSONObject result = new HashMap();
String classIndex = "class%s";
for (int i = 0; i names.length; i++) {
String classKey = String.format(classIndex, Integer.parseInt(String.valueOf(i / 10)) + 1);
JSONObject person = new JSONObject();
person.put("id", StringUtils.leftPad(String.valueOf(i + 1), 5, "0"));
person.put("name", names[i]);
person.put("class", classKey);
ListJSONObject classValues = result.get(classKey);
if (null == classValues) {
classValues = new ArrayList();
classValues.add(person);
result.put(classKey, classValues);
} else {
classValues.add(person);
}
}
System.out.println(JSONObject.toJSONString(result));
}
如何用java语言编写一个叫学号器,比如班里有五十个同学,按一下按钮,随机叫出一个同学的名字!求详细代
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class test extends JFrame{
String[] student;
JLabel jl;
test(String[] s){
student=s;
JPanel jp=new JPanel();
JButton jb=new JButton("叫号");
jl=new JLabel();
jp.add(jb);
jp.add(jl);
this.getContentPane().add(jp);
jb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jl.setText(student[(int)Math.floor(Math.random()*50)]);
}
});
this.setTitle("叫号器");
this.setSize(200,100);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.setVisible(true);
}
public static void main(String[] args)throws Exception {
String[] student=new String[50];
for (int i = 0;i student.length; i++) {
student[i] = "小"+(int)Math.floor(Math.random()*50);
}
new test(student);
}
}
Java 定义一个学生类,属性包括:学号,姓名,年龄,班级和电话,设计所有变量的get set方
完整代码如下,复制到eclipse中运行:publicclassStuExam{privateStringsnum;//学号privateStringcnum;//班号privateStringname;//姓名privatecharsex;//性别privateintage;//年龄//get/set方法用来获取/设置学生实例对象的
java 假设一个班级共35人, 学号从1~35, 请编写程序进行随机学号抽取, 每个学号不
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class SelectNo {
public static void main(String[] args) {
//将1-35号码放入List集合
ListString list = new ArrayListString();
for (int i = 1; i 36; i++) {
list.add(""+i);
}
//新建一个List集合用来存放抽出来的号码
ListString newList = new ArrayListString();
//随机抽取list集合中的一个元素,抽出后删除
Random rd = new Random();
int count = list.size();//集合中剩余号码
while (count 0) {
int index = rd.nextInt(count);//抽出的号码的位置
//放入新的集合
newList.add(list.get(index));
//删除原有集合的元素
list.remove(index);
count--;//原有集合少了一个
}
//输出号码
for (int i = 0; i newList.size(); i++) {
System.out.print(newList.get(i)+"\t");
//每五个换行
if(i%5 == 4){
System.out.println("");
}
}
}
}
分配学号java的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于学号是怎么安排的、分配学号java的信息别忘了在本站进行查找喔。