标签:eof 随机数 `` import port pack str system tin
package com.homework.demo01;
import java.util.Random;
public class Demo08 {
public static void main(String[] args) {
String s = a();
String s1 = a();
String s2 = a();
String s3 = a();
System.out.println(s);
System.out.println(s1);
System.out.println(s2);
System.out.println(s3);
}
private static String a() {
Random random = new Random();
//定义长度为8的数组
int[] arr = new int[8];
for (int j = 0; j < arr.length; j++) {
//生成0到9的随机数
int i = random.nextInt(10);
arr[j]=i;//把随机数赋值给数组中每一个元素
for (int k = 0; k < j; k++) { //遍历数组中储存进去的值,有几个值就循环几次
if(arr[k]==arr[j]){ //是否有相等的值
j--; //数组的索引-1,循环次数回到上次
break;
}
}
}
String str = "";
for (int i : arr) {
String s = String.valueOf(i);
str+=s;
}
return str;
}
}
``` java
标签:eof 随机数 `` import port pack str system tin
原文地址:https://www.cnblogs.com/liqiliang1437/p/13077094.html