结果小于0是因为你的整数超出了int的范围
package www.itlanguageexpress.info;
public class WhileInput {
/**
* @param args
*/
public static void main(String[] args) {
int max = 0;
int min = 0;
int rint = (int) (Math.random()*1000);
int count = 0;
while(rint != 0) {
if(count == 0) {
max = rint;
min = rint;
count++;
}else {
max = rint > max?rint:max;
min = rint < min?rint:min;
}
rint = (int) (Math.random()*1000);
}
System.out.println("max=" + max + "; min=" + min);
}
}
。。你把做为结束符的0也算进去了吧。
在循环里判定一下,如果是0不做MIN==NUM
if(NUM!=0)MIN = MIN
把你的代码发上来看看