Random r = new Random(); int temp[] ={0,0,0,0,0,0,0,0,0,0}; String fourNum=""; while(fourNum.length()!=9){ int t = r.nextInt(9); if(temp[t]==0){ fourNum+=t; temp[t]=1; } }System.out.println(fourNum);