大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
//首先我们可以先把名字搞成一个数组,或者List都是可以的。
成都创新互联于2013年创立,先为玉门等服务建站,玉门等地企业,进行企业商务咨询服务。为玉门企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
String[] arr = {"张三","李四","王五","xxx"....};
String random = arr[new Random().nextInt(arr.size())];
System.out.println("随机名字为:"+random);
import java.io.BufferedInputStream;import java.util.Scanner; public class test1 { public static void main(String[] args) { Scanner cin = new Scanner(new BufferedInputStream(System.in)); int n = cin.nextInt(); // 输入n个数 int[] a = new int[n]; for (int i = 0; i n; ++i) { a[i] = cin.nextInt(); } cin.close(); for (int i = a.length - 1; i = 0; --i) { // 逆序输出 System.out.print(a[i] + " "); } }}
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
public class test_random extends JFrame implements ActionListener{
public static void main(String[] args) {
test_random t = new test_random();
t.init();
}
public void init(){
initListDate();
but = new JButton("开始点名");
but.setBounds(100,150,100,40);
but.addActionListener(this);
label = new JLabel("随机点名");
label.setBounds(60,20,300,40);
label.setFont(new Font("楷体",Font.BOLD,40));
show = new JLabel("");
show.setBounds(110,80,200,30);
show.setFont(new Font("楷体",Font.BOLD,30));
reset = new JButton("重新点名");
reset.setBounds(203,246,90,25);
reset.addActionListener(this);
add(but);
add(label);
add(show);
add(reset);
setLayout(null);
setVisible(true);
setResizable(false);
setBounds(100,100,300,300);
setTitle("点名");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void initListDate(){
//在这个地方添加姓名就可以了
list.add("刘天廷");
list.add("孔老二");
list.add("张三");
list.add("李四");
list.add("王五");
list.add("麻六");
list.add("冯七");
list.add("京八");
list.add("茅台九");
}
public void actionPerformed(ActionEvent e) {
/*确保每人选一次*/
Object obj = e.getSource();
if(obj == but){
if(list.size()==0){
JOptionPane.showMessageDialog(null,"没有人了!");
return ;
}else{
Random ran = new Random();
int num = ran.nextInt(list.size());
show.setText(list.get(num));
list.remove(num);
}
}
if(obj == reset){
show.setText("");
initListDate();
}
}
private JButton but ;
private JLabel label;
private JLabel show;
private JButton reset;
private ListString list = new ArrayListString();
}