写一个程序,产生25个int类型的随机数,对于每一个随机数,使用if-else语句来将其分类大于、等于、或等于紧随它而随机生成的值。答案如下,我不明白又声明RDN3,4干什么。。跟上边的不是一样么public class CompareInts {public static void main(String[] args) {Random rand1 = new Random();Random rand2 = new Random();for(int i = 0; i < 25; i++) {int x = rand1.nextInt();int y = rand2.nextInt();if(x < y) print(x + " < " + y);else if(x > y) print(x + " > " + y);else print(x + " = " + y);}Random rand3 = new Random();Random rand4 = new Random();for(int i = 0; i < 25; i++) {int x = rand3.nextInt(10);int y = rand4.nextInt(10);if(x < y) print(x + " < " + y);else if(x > y) print(x + " > " + y);else print(x + " = " + y);}}
添加回答
举报
0/150
提交
取消