各位大哥大姐大虾们~帮帮小弟看看问题在哪 滴水之恩当涌泉相报

rong345867727 2011-06-15 10:28:21
import java.io.*;
public class abc
{
public static void main (String args[])
{int i,n=10,max=0,min=0,temp=0;
try {
BufferedReader br=new BufferedReader (
new

InputStreamReader(System.in));
max =min=Integer.parseInt(br.readLine());

}
catch (IOException e){};
for(i=2;i<=n;i++){
try {BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
temp=Integer.parseInt(br.readLine());
if(temp>max)
max=temp;
if(temp<max)
min=temp;}

catch (IOException e){}

}

System.out.println("max="+max+"\nmin="+min);
}
} //这是求从10输入数中比较最大和最小的值进行输出,编译通过,可是结果不对啊!错在哪里啊??








...全文
96 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
rong345867727 2011-06-17
  • 打赏
  • 举报
回复
哦哦,,,
飞跃颠峰 2011-06-17
  • 打赏
  • 举报
回复
那个颜色是CSDN网站弄的,与我无关哈
rong345867727 2011-06-17
  • 打赏
  • 举报
回复
行啦!是我搞错了!我按空格键了!我菜鸟的,不见怪啊!谢谢你!还有怎样格式化代码??就是像你的那样会显示颜色的!
飞跃颠峰 2011-06-17
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 rong345867727 的回复:]

还是不行啊!!!没有输出!
[/Quote]

根据程序代码,你必须先输入10个数,每输入一个按一次回车,然后才能看到输出
rong345867727 2011-06-17
  • 打赏
  • 举报
回复
还是不行啊!!!没有输出!
飞跃颠峰 2011-06-15
  • 打赏
  • 举报
回复
错误1: max=min=...这句
错误2: if(temp<max) min=temp; 改成 if(temp<min) min=temp;

上面就改了这两个错误,就对了
飞跃颠峰 2011-06-15
  • 打赏
  • 举报
回复

import java.io.*;
public class abc
{
public static void main (String args[])
{
int i,n=10,max=0,min=0,temp=0;
try {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
max=Integer.parseInt(br.readLine());
min = max;
}
catch (IOException e){};

for(i=2;i<=n;i++){
try {BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
temp=Integer.parseInt(br.readLine());
if(temp>max)
max=temp;
if(temp<min)
min=temp;}

catch (IOException e){}
}
System.out.println("max="+max+"\nmin="+min);
}
}

51,409

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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