当前位置: 代码迷 >> Java相关 >> [求助]大家帮忙看看这个程序
  详细解决方案

[求助]大家帮忙看看这个程序

热度:254   发布时间:2007-04-03 16:30:31.0
[求助]大家帮忙看看这个程序

大家看看,这个程序有错吗?
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class InputStringTwo {

/**
* @param args
* @throws IOException
* @throws NumberFormatException
*/
public static void main(String[] args) throws NumberFormatException, IOException {
// TODO 自动生成方法存根
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int i,max=0,min;
int a[]=new int[5];
System.out.println("请输入五个数:");
for(i=0;i<a.length;i++)
{
a[i]= Integer.parseInt(br.readLine());
}

for(i=0;i<a.length;i++)
if(a[i]>max){
max=a[i];
}
min=a[0];
for (i=0;i<a.length;i++){
if (min>a[i]){
min=a[i];
}
}
System.out.println("max="+max);
System.out.println("min="+min);
}
}
还有,BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 是什么意思?
new InputStreamReader(System.in); 又是什么意思/

搜索更多相关的解决方案: public  import  public  import  

----------------解决方案--------------------------------------------------------
还有,BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 是什么意思?
new InputStreamReader(System.in); 又是什么意思/

都是根据System.in构造一个输入流
System.in是控制台的标准输入
----------------解决方案--------------------------------------------------------

import java.util.*;

public class sort {

public static void main(String[] args)
{
// TODO Auto-generated method stub
int[] a= new int[5];
Scanner s=new Scanner(System.in);
for(int i=0;i<a.length;i++)
{
System.out.println("输入5个数:");
a[i]=s.nextInt();
}
Arrays.sort(a);
System.out.println("最大值"+a[a.length-1]);
System.out.println("最小值"+a[0]);

}

}


----------------解决方案--------------------------------------------------------

对数组排序吧!!


----------------解决方案--------------------------------------------------------
  相关解决方案