欢迎访问桃李自考网,本站可为自考生提供学习指导服务,今天是

您所在的位置: 首页> 备考指导 > 模拟试题 > 工学类 > java语言程序设计(一) > 2018年自考《Java语言程序设计》综合练习题三

2018年自考《Java语言程序设计》综合练习题三

发表时间:2022-07-08 15:01:02 来源:桃李自考网
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++ )

                        if  ( a[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);  }  }