Java面向对象程序设计复习题附答案解析

2. 编写一个Application,接受用户从键盘输入的10个整数,并输出这10个整数的最大值和最小值。

mport java.io.* ; public class abc {

public static void main(String args[ ]) { int i , n = 10 , max = 0 , min = 0 , temp = 0; try {

BufferedReader br = new BufferedReader(

new InputStreamReader(System.in)); max = min = Integer.parseInt(br.readLine( )); } catch ( IOException e ) { } ; for ( i = 2 ; i <= n ; i ++ ) { try {

BufferedReader br = new BufferedReader(

new InputStreamReader(System.in)); temp = Integer.parseInt(br.readLine( )); if (temp > max ) max=temp; if (temp < min) min=temp; } catch ( IOException e ) { } ;

}

System.out.println(\ } }

3. 从标准输入(即键盘)读入10个整数存入整型数组a中,然后逆序输出这10个整数。

import java.io.* ;

public class Reverse

{ public static void main(String args[ ]) { int i , n =10 ;

int a[ ] = new int[10]; for ( i = 0 ; i < n ; i ++ ) try {

BufferedReader br = new BufferedReader( new InputStreamReader(System.in));

a[i] = Integer.parseInt(br.readLine( )); // 输入一个整数 } catch ( IOException e ) { } ; for ( i = n-1 ; i >= 0 ; i ―― ) System.out.print(a[i]+\ \ System.out.println( ); } }

4. 编程题(略)

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4