代码如下:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Max_Min {
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<min)min=temp;
} catch (IOException e) {}
}
System.out.println("max=" +max+"\\nmin="+min);
}}怎么就数不结果了,请高手讲解!

解决方案 »

  1.   

    try {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));max=min=Integer.parseInt(br.readLine());} catch (IOException e) { }
    改为for(int i=0;i<10;i++){
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));max=min=Integer.parseInt(br.readLine());} catch (IOException e) { }
    }
      

  2.   

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;public class Max_Min {
    public static void main(String[] args){
    BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
    int max=0;
    int min=10000000; for(int i=0;i<10;i++){
    try {
    int c=Integer.parseInt(bf.readLine());
    if(c>max){
    max=c;
    }
    if(c<min){
    min=c;
    }
    //System.out.println();
    }
    catch (NumberFormatException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    System.out.println("Max number:"+max);
    System.out.println("Min number:"+min);
    }
    }
    那个最小的写的不怎么好,局限于开始设置的初始值,没时间了,你自己看下吧,反正流程是这样!
    在控制台没输入一个数字 回车
    直到输出10数字后显示最大值和最小值
      

  3.   


    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.List;
    import java.util.Scanner;
    public class Max_Min {
    public static void main(String[] args) {
    Scanner scan=new Scanner(System.in);
    int count=1;
    List<Integer> list=new ArrayList<Integer>();
    while(count<11){
    System.out.println("请输入第"+count+"个数字");
    list.add(scan.nextInt());
    count++;
    }
    Collections.sort(list);
    System.out.println("Min:"+list.get(0));
    System.out.println("Max:"+list.get(list.size()-1));
    }
    }
      

  4.   

    import java.util.ArrayList;
    import java.util.List;
    import java.util.Scanner;/**
     *
     * @author HeYiding
     */
    public class ScannerDemo {    public static void main(String[] args) {
            // 获取用户输入
            String prompt = "请输入任意多个数字,用空格隔开:";
            List<Integer> ints = readNumbers(prompt);        // 查找最大最小值
            Integer max = null, min = null;
            for (Integer i : ints) {
                if (max == null || i > max) {
                    max = i;
                } else if (min == null || i < min) {
                    min = i;
                }
            }        System.out.println("最大值: " + max + ", 最小值: " + min);
        }    /**
         * 读取用户输入的数字,数字以空格隔开
         *
         * @param prompt 提示信息
         *
         * @return 用户输入的数字
         */
        private static List<Integer> readNumbers(String prompt) {
            List<Integer> result = new ArrayList<Integer>();        System.out.println(prompt);
            Scanner scanner = new Scanner(readLine());
            while (scanner.hasNextInt()) {
                result.add(scanner.nextInt());
            }        return result;
        }    private static String readLine() {
            Scanner lineReader = new Scanner(System.in);
            String line = lineReader.nextLine();
            return line;
        }
    }