大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
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] + " "); } }}
专业从事成都网站设计、成都网站制作、外贸网站建设,高端网站制作设计,微信小程序定制开发,网站推广的成都做网站的公司。优秀技术团队竭力真诚服务,采用H5页面制作+CSS3前端渲染技术,自适应网站建设,让网站在手机、平板、PC、微信下都能呈现。建站过程建立专项小组,与您实时在线互动,随时提供解决方案,畅聊想法和感受。
//首先我们可以先把名字搞成一个数组,或者List都是可以的。
String[] arr = {"张三","李四","王五","xxx"....};
String random = arr[new Random().nextInt(arr.size())];
System.out.println("随机名字为:"+random);
import java.util.Random;
public class RandomD {
public static void main(String[] args) {
System.out.println("随机点名开始!我将要在5个同学中点名!");
String[] student={"张三","李四","王五","麻子","小猪"};
Random rand=new Random();
System.out.println("点名开始:");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(student[Math.abs(rand.nextInt()%5)]);
}
}
试下我的,跟你的效果一样
public static void main(String args[]){
String[] namelist={"小明","小白","小黑","小黄","小兰","小草","小丽","兔子","巫妖","船长","剑圣","冰女"};
Random r = new Random();
int f = r.nextInt(namelist.length);
System.out.println(namelist[f]);
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();
}