日期:2014-05-20 浏览次数:20666 次
public class TestInput { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int max = Integer.MIN_VALUE; int min = Integer.MAX_VALUE; System.out.print("请输入一个整数(输入0结束)"); while (scanner.hasNext()) { try { int temp = scanner.nextInt(); if (temp == 0) break; if (temp > max) max = temp; if (temp < min) min = temp; System.out.print("请输入一个整数(输入0结束)"); } catch (Exception e) { try { throw new Exception("输入错误"); } catch (Exception e1) { e1.printStackTrace(); } } } System.out.println("最大值为:"+ max+" 最小值为:" + min); } }