ITeye博客

JAVA随机数Random

caryt · 2013-06-27 11:15 · Markdown

/**
*
* @author caryt
*
*/
public class test {

/**
* @param args
*/
static int x[]=new int[15];
public static void main(String[] args) {
// TODO Auto-generated method stub
Random random=new Random();
int x = 0,y = -1;
do {
x=random.nextInt(10);//0~10;
y=random.nextInt(10);
System.out.println("x: "+x+" y: "+y);

}while (x!=y);

}

}

out:x: 2 y: 3
x: 0 y: 6
x: 8 y: 7
x: 4 y: 5
x: 8 y: 8

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。