您的位置:首页 > 其它

彩票问题 不输出相同的数字

2016-01-15 22:02 218 查看
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);

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: