请教两道问题?
bj518 2007-09-21 10:35:38 /* 创建一个整数数组,数组大小随机产生,数组里面的整数也是随机产生的
1-1000之间的整数。*/
//这道题我怎么也不知道应该如何获得随机数,希望大家多多指点,最好加点注释
public class suijishu {
public static void main(String[] args){
int[] random = new int[];
for(int i=0;i<random.length;i++){
random[i] = (int)(Math.random()*1000) + 1;
System.out.print(random[i] + " ");
}
System.out.println();
}
}
/* 编写一个猜数字的程序,先随机产生一个1-100之间的整数,接着请用户输入猜的数字,如果猜大了就显示:“大了!”,猜小了就显示“小了!”,然后继续猜,直到猜对为止。 */
// 这道题如何让它猜对就截止
mport java.util.Scanner;
public class caidaxiao {
public static void main(String[] args){
int i;
int shu;
int[] random;
do{
System.out.print("请输入数字:");
Scanner scan = new Scanner(System.in);
shu = scan.nextInt();
random = new int[100];
for(i = 0;i < random.length;i++){
random[i] = (int)(Math.random()*100) + 1;
if(shu < random[i]){
System.out.println("小了!");
break;
}
else if(shu > random[i]){
System.out.println("大了!");
break;
}
}
}while(shu == random[i]);
}
}