菜鸟问题:从键盘读取多个数,并打印它们的和及最大最小值

lukang2008 2006-10-18 12:58:36
从键盘读取多个数,并打印它们的和及最大最小值
大家帮下忙!
我可以求出他们的和
但是要怎么判断起那么多数字的最大最小呢?
用排列吗???
...全文
169 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
learner_007 2006-10-19
  • 打赏
  • 举报
回复
mark
dashi 2006-10-18
  • 打赏
  • 举报
回复
up~~~
lip009 2006-10-18
  • 打赏
  • 举报
回复
public class Count {
public static void main(String args[]) {
int min = 0;
int max = 0;
int count = 0;
String s = "";
int i=0;

while (true) {
char n=0;
try {
if ("exit".equals(s)) {
break;
}
n = (char) System.in.read();
}
catch (Exception ex1) {
}

if (n == '\n') {
try {
int current = Integer.parseInt(s);
if(i==0){
min=current;
max=current;
}
if (min > current) {
min = current;
}
if (max < current) {
max = current;
}
count = count + current;
}
catch (NumberFormatException ex) {
System.out.println("请输入一个整数");
}
s = "";
i++;
continue;
}
else {
s = s + n;
}
}

System.out.println("最大数:"+max);
System.out.println("最小数:"+min);
System.out.println("和:"+count);
}
}

23,407

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧