/**
*
* @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);
*
* @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
本文介绍了一个简单的Java程序,该程序使用随机数生成器生成两个介于0到9之间的随机整数,并持续进行比较,直到这两个数相等。通过打印每次生成的随机数,可以观察到程序运行的过程。
442

被折叠的 条评论
为什么被折叠?



