java中我要实现在1-9里面随机出现5个不一样的数

来源:百度知道 编辑:UC知道 时间:2024/06/27 22:46:57
我要实现
1-9里面随机出现不一样的7个数.
import java.util.Random;
class ZW {

public static void main(String []args)
{
int a;

Random z=new Random();
int arr[]={1,2,3,4,5,6,7,8,9};
a = Math.abs(z.nextInt())%9;

{
{
for(int i=0;i<5;i++)

{
if(i==a)
{

System.out.println(arr[a]);}
}
}
}
}
} 缺了哪些代码?我现在的代码只能实现随即出现一个数字

class ZW {

public static void main(String[] args) {
int a;

for (int i = 0; i < 5; i++)

{
Random z = new Random();
int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
a = Math.abs(z.nextInt()) % 9;
{
System.out.println(arr[a]);
}
}
}
}