public class TestCar { public static void main(String[] args) { // TODO 自动生成的方法存根 int[] cp = new int[7]; Random r = new Random(); r.nextInt(36); for (int i = 0; i < cp.length; i++) { int t = r.nextInt(36); if(t == 0) { i--; continue; } else { boolean h = false; for(int c : cp) { if(c == t) { i--; h = true; break; } } if(h) { continue; } } cp[i] = t; } for (int c : cp) { System.out.print(c + " "); } } }
public class TestCar { public static void main(String[] args) { // TODO 自动生成的方法存根 int[] cp = new int[7]; Random r = new Random(); String str = ""; for (int i = 0;i <cp.length;i++) { int t = r.nextInt(36); if(t == 0) { i--; continue; } else { if(str.indexOf(""+t) >= 0) { i--; continue; } } str = str + t +" "; } System.out.print(str); } }
时间: 2024-10-09 06:14:12