日期:2014-05-20 浏览次数:20819 次
题目是:编写应用程序,用字符界面接受用户10个数字输入,输出这10个整数的最大值和最小值。
程序如下:
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class TestOutput { public static void main(String[] args) { int dataArray [] = new int [10]; int maxData = 0,minData = 0; try{ InputStreamReader stdin = new InputStreamReader(System.in); BufferedReader bufferin = new BufferedReader(stdin); for (int i = 0; i < dataArray.length; i++) { System.out.print("请输入第"+ (i+1) + "个数:"); dataArray[i] = Integer.valueOf(bufferin.readLine()).intValue(); } maxData = minData = dataArray[0]; for (int i = 1; i < dataArray.length; i++) { if(maxData < dataArray[i]){ maxData = dataArray[i]; } if(minData > dataArray[i]){ minData = dataArray[i]; } } System.out.println("最大值是:" + maxData); System.out.println("最小值是:" + minData); }catch(IOException ioe){ ioe.printStackTrace(); } } }
?