- package com.itheima;
 
  
- import java.io.BufferedReader;
 
 - import java.io.IOException;
 
 - import java.io.InputStreamReader;
 
  
 
 
- /*
 
 -  * 第七题、 编写程序接收键盘输入的5个数,装入一个数组,并找出其最大数和最小数。
 
 -  * 思路:        
 
 -  */
 
 - public class Text7
 
 - {
 
 -         public static void main(String args)
 
 -         {
 
 -                 getNumber();
 
 -         }
 
 -         
 
 -         public static void getNumber()  
 
 -         {
 
 -                 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
 -                 
 
 -                 int[] arr = new int[5];
 
  
-                 int count = 0;
 
 -                 
 
 -                 try
 
 -                 {
 
 -                         String line = br.readLine();
 
 -                         
 
 -                         while(line!=null)
 
 -                         {
 
 -                                 int num = Integer.parseInt(line);
 
 -                                 
 
 -                                 arr[count] = num;
 
 -                                 
 
 -                                 count++;
 
 -                                 
 
 -                                 if(count==5)
 
 -                                 {
 
 -                                         break;
 
 -                                 }
 
 -                         }
 
 -                         
 
 -                 arr = sortArr(arr);        
 
 -                 
 
 -                 int min = arr[0];
 
 -                 int max = arr[arr.length-1];
 
 -                 
 
 -                 System.out.println(min);
 
 -                 System.out.println(max);
 
 -                 
 
 -                 br.close();
 
 -                 
 
 -                 } 
 
 -                 catch (IOException e)
 
 -                 {
 
 -                         System.out.println("异常情况,请正确输入");
 
 -                 }
 
 -         }
 
 -         
 
 -         public static int[] sortArr(int[] arr)
 
 -         {
 
 -                 int temp = 0;
 
 -                 
 
 -                 for(int i=0; i<arr.length-1; i++)
 
 -                 {
 
 -                         if(arr[i]>arr[i+1])
 
 -                         {
 
 -                                 temp = arr[i];
 
 -                                 arr[i] = arr[i+1];
 
 -                                 arr[i+1] = temp;
 
 -                         }
 
 -                 }
 
 -                 
 
 -                 return arr;
 
 -         }
 
 - }
 
  
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  复制代码 |