- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.io.IOException;
- public class Compare
- {
- public static void main(String[] args)
- {
- BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
- int []a=new int[3];
- int min=a[0],max=a[0];
- for(int i=0;i<a.length;i++)
- {
- try
- {
- System.out.print("请输入第"+(i+1)+"个数:");
- a[i]=Integer.parseInt(br.readLine());
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- }
-
- for(int i=0;i<a.length;i++)
- {
- if(a[i]>max)
- {
- max=a[i];
- }
- if(a[i]<min)
- {
- min=a[i];
- }
- }
- System.out.println("最大值为:"+max+"\n最小值为:"+min);
- }
- }
复制代码 |