标签:
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); } }
标签:
原文地址:http://www.cnblogs.com/yifangtongxing/p/5134604.html