2018年自考《Java语言程序设计》综合练习题三
三、写出下列程序完成的功能。
1. public class Sum
{ public static void main( String args[ ])
{ double sum = 0.0 ;
for ( int i = 1 ; i <= 100 ; i + + )
sum += 1.0/(double) i ;
System.out.println( 'sum='+sum );
}
}
2.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( );
}
}
3.import java.awt.*;
public class abc
{ public static void main(String args[])
{ new FrameOut(); }
}
class FrameOut extends Frame // Frame为系统定
{ Button btn; // 义的窗框类
FrameOut( )
{ super('按钮');
btn = new Button('按下我');
setLayout(new FlowLayout( ));
add(btn);
setSize(300,200);
show( );
}
}
4. import java.io.*;
public class Class1
{
public static void main(String args[ ]){
int i , Max , Min ;
int a[ ] = { 12,67,8,98,23,56,124,55,99,100 };
Max = Min = a[0];
for ( i = 1 ; i < a.length; i ++ ) {
if ( a[i] if ( a[i]>Max ) Max = a[i]; } System.out.println( Max+' '+Min ); System.out.println( ); } } 5. public class ABC { public static void main(String args[ ]){ int i , j ; int a[ ] = { 12,67,8,98,23,56,124,55,99,100 }; for ( i = 0 ; i < a.length-1; i ++ ) { int k = i; for ( j = i ; j < a.length ; j++ )