使用for循环和if条件判断实现名字随机
public class ForName {
public static void main(String[] args) {
String names[] = {"画临","崎沐","若青","汤饼","初度","生小","总角","垂鬓","始龄","外博","束发",
"舞勺","豆蔻","及笄","舞象","待年","弱冠","而立",
"不惑","知命","花甲","古稀","皓首","耄耋","黄发","鲐背","期颐"};
int number[] = new int[0];
int ind = 0;
int count = 0;
for (; number.length < names.length ;){
boolean rule = true;
int index = (int)(Math.random() * names.length);
for (int num : number) {
if(num ==index){
rule = false;
break;
}else{
rule = true;
}
}
if(rule){
if(number.length<=names.length) {
number = Arrays.copyOf(number, number.length + 1);
count++;
number[ind] = index;
ind++;
}
if(count%6==0){
System.out.println(names[index]);
}else{
System.out.print(names[index]+"\t");
}
}else{
continue;
}
}
}
}