package cn.edu.bjut.chapter5; public class MinMax { public static void main(String[] args) { int maxVal, submaxVal; int a[] = { 8, 50, 20, 7, 81, 55, 76, 93 }; if (a[0] > a[1]) { maxVal = a[0]; submaxVal = a[1]; } else { maxVal = a[1]; submaxVal = a[0]; } for (int i = 2; i < a.length; i++) { if (a[i] > maxVal) { submaxVal = maxVal; maxVal = a[i]; } else if (a[i] > submaxVal) { submaxVal = a[i]; } } System.out.println(maxVal + "\t" + submaxVal); } }