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++ )
int temp =a[i];
a[i] = a[k];
a[k] = temp;
}
for ( i =0 ; i
System.out.print(a[i]+' ');
System.out.println( );
}
}
6.import java.io.*;
public class Class1 {
public static void main( String args[] )
{
Fact N = new Fact( 4 );
System.out.println( N.fact( ) );
}
}
class Fact {
int n ;
Fact( int nn ) { n = nn; }
int fact( ) {
int i , f = 1;
for ( i=1; i<=n; i++ )
f = f*i;
return f;
}
}
7.import java.awt.*;
import java.applet.Applet;
public class DrawMyImage extends Applet
{
Image myImage; // 定义一个图像类Image的对象myImage
public void init( )
{
myImage = getImage(getDocumentBase( ),'pica.jpg');
}
public void paint(Graphics g)
{
g.drawImage(myImage,0,0,this);
}
}
8. import java.io.*;
public class Class1 {
public static void main( String args[ ] )
{ SubClass a = new SubClass( 10,3 );
System.out.println( a.exp( ));
}
}
class SuperClass {
float x;
int n;
SuperClass( float xx , int nn ) { x = xx ; n = nn; }
}
class SubClass extends SuperClass {
SubClass( float xx , int nn ) { super( xx , nn ); }
float exp( ) {
float s = 1;
for ( int i = 1; i<=n; i++ ) s = s*x;
return s;
}
}
9. import java.awt.*;
import java.applet.Applet;
public class Applet1 extends Applet
{
public void paint( Graphics g )
{
g.drawLine( 30,5,100,45 );
g.drawRect( 30,50,50,20 );
g.drawOval( 30,80,50,40 );
g.drawString( 'They are figures!' , 30,150 );
}
}
10.import java.io.*;
public class abc
{ public static void main(String args[])
{ SubClass sb = new SubClass( );
System.out.println(sb.max( ));
}
}
class SuperClass
{ int a = 10 , b = 20 ; }
class SubClass extends SuperClass
{ int max( ) { return ((a>b)?a:b); } }
(一)由于考试政策等各方面情况的不断调整与变化,本网站所提供的考试信息仅供参考,请以权威部门公布的正式信息为准。
(二)本网站在文章内容来源出处标注为其他平台的稿件均为转载稿,免费转载出于非商业性学习目的,版权归原作者所有。如您对内容、版权等问题存在异议请与本站联系,我们会及时进行处理解决。