java随机字符串生成?
代码如下,供参考:
import java.util.Random;public class Main { public static void main(String[] args) { char[] chs = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}; String str = new Main().getStr(chs); System.out.println(str); } public String getStr(char[] chs) { String str = ""; Random random = new Random(); for (int i = 0; i < 4; i++) { // 这种写法易于扩展,chs内容改了不用修改代码 str += chs[random.nextInt(chs.length)]; } str += random.nextInt(10); return str; }}
java作业 随机产生20~50之间的整数10个,并存放在一维数组中,调用方法:实现数组元素向左循环移位?
public class test_2 { public static void main(String[] args) { int[] a = new int[10]; for (int i = 0; i
用java生成0-9之间的随机整数,并统计个数出现的次数?
0出现次数:10031出现次数:9532出现次数:9963出现次数:10284出现次数:10105出现次数:10136出现次数:10397出现次数:10008出现次数:9739出现次数:985
java怎么使用随机抽取数组里的数据?
Random r = new Random();
System.out.println(b[r.nextInt(3)]);r.nextInt(3);就是随机取得0 1 2这三个数中的其中一个,然后当做你数组的下标,就随机抽取了

