ZKX's LAB

java如何做一个随机抽取学号小程序 java随机抽取代码

2020-12-15知识3

用java写一段随机抽取3个人的代码 用java.util.Radom类中的方法.Random rd=new Random();int persion_id=rd.nextInt(10);这样可以得到0-10之间的一个随机数(假如总共有十个学生.)然后用,threeStudent.add。

java如何做一个随机抽取学号小程序 java随机抽取代码

用Java编程从1-19里随机抽取一个数的程序~~~求救 import java.util.HashMap;import java.util.Map;import java.util.Random;public class DbColorBall {HashMap,String>;map=new HashMap,String>;();private void getNums(){Random r=new Random();int i=r.nextInt(19);String s;if(i>;0&。map.containsKey(String.valueOf(i))){if(i){s=\"0\"+i;} else {s=String.valueOf(i);}map.put(String.valueOf(i),s);} else {getNums();}}public void showResult(){for(int i=0;i;i+){getNums();}for(Map.Entry,String>;entry:map.entrySet()){System.out.println(entry.getValue());}}public static void main(String[]args){DbColorBall dbColorBall=new DbColorBall();dbColorBall.showResult();}}

java如何做一个随机抽取学号小程序 java随机抽取代码

用java程序的if else语句模拟从一副52张牌中随机抽出一张牌,程序应该输出牌的花色和大小。 import java.util.Arrays;import java.util.Scanner;public class Poker {private static final int NUM=1;private static int SUM=52;private static final String P=\"A,2,3,4,5,6,7,8,9,10,J,Q,K;private static String[][]POKER={P.replaceAll(\"([^,]+)\",\"黑桃$1\").split(\",\"),P.replaceAll(\"([^,]+)\",\"红桃$1\").split(\",\"),P.replaceAll(\"([^,]+)\",\"梅花$1\").split(\",\"),P.replaceAll(\"([^,]+)\",\"方片$1\").split(\",\")};public static void main(String[]args){Scanner scanner=new Scanner(System.in);int count=NUM;String[]hand=new String[0];System.out.println(\"随机发\"+count+\"张牌\");SUM-=count;for(int i=0;i;i+){int row=(int)(Math.random()*POKER.length);int col=(int)(Math.random()*POKER[row].length);String[]css=new String[hand.length+1];System.arraycopy(hand,0,css,0,hand.length);css[css.length-1]=POKER[row][col];hand=css;}System.out.println(\"然后看手里的牌:\");System.out.println(Arrays.toString(hand));scanner.close();}}

java如何做一个随机抽取学号小程序 java随机抽取代码

Java随机抽取人名完整代码是什么? public public class test { public static void main(String[]args){/定义人名数组 String[]name={\"张三\",\"李四\",\"王五\",\"八神庵\",\"不知火舞\",\"大蛇\",\"景天\",\"唐雪见\",。

java怎么使用随机抽取数组里的数据? Random r=new Random();System.out.println(b[r.nextInt(3)]);r.nextInt(3);就是随机取得0 1 2这三个数中的其中一个,然后当做你数组的下标,就随机抽取了 package reptile;。

使用java编写随机数抽奖小程序,本篇经验介绍如何用java编写一个简单的随机数字抽奖器,主要用到的知识是Swig编程和线程知识,最终程序开始界面如下图:

java如何做一个随机抽取学号小程序 程序代码:http://pan.baidu.com/s/1eQmrI7o 方法/步骤 1 功能:根据你输入的学号总数,点击开始,中间的结果就根据学号的总数不停变化,点击停止,结果停止变动, 2 分析。

用java编写一段代码,随机抽出2个班中的学生来提问 public class Test {public static void main(String args[]){System.out.print(Math.round(Math.random()*1)+1+\"班级中\");System.out.print(Math.round(Math.random()*29)+1+\"号学生\");}}

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集合List<;String>;list=new ArrayList();for(int i=1;i;i+){list.add(\"\"+i);}新建一个List集合用来存放抽出来的号码List<;String>;newList=new ArrayList();随机抽取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();i+){System.out.print(newList.get(i)+\"\\t\");每五个换行if(i%5=4){System.out.println(\"\");}}}}

java怎么使用随机抽取数组里的数据? Random r=new Random();System.out.println(b[r.nextInt(3)]);r.nextInt(3);就是随机取得0 1 2这三个2113数中的其中一个5261,然后当做你数组的4102下标,就随1653机抽取了

随机阅读

qrcode
访问手机版