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

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

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

发表时间:2022-07-28 13:52:41 来源:桃李自考网
2018年自考《Java语言程序设计》综合练习题四

四、写出下面程序的运行结果。

1.import    java.io.*;

public  class  abc

{     public  static  void  main(String args[ ])

      {    AB  s = new  AB('Hello!','I love JAVA.');

           System.out.println(s.toString( ));

      }

}

class   AB {

  String   s1;

  String   s2;

  AB( String  str1 , String  str2 )

  {  s1 = str1;  s2 = str2; }

  public   String   toString( )

  { return  s1+s2;}

}

 

 

2.import    java.io.* ;

    public   class  abc

    {

          public   static   void    main(String  args[ ])

          {    int   i , s = 0 ;

               int  a[ ] = { 10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 , 90 };

               for  ( i = 0 ; i < a.length ; i ++ )

                     if ( a[i]%3 = = 0 )  s += a[i] ;

               System.out.println('s='+s);

           }

     }

 

3. import   java.io.* ;

     public  class  abc

     {

          public  static  void   main(String  args[ ])

          {  SubSubClass  x = new  SubSubClass(10 , 20 , 30);

             x.show();

          }

     }

    class  SuperClass

    {   int  a,b;

        SuperClass(int aa , int  bb)

         {  a=aa;  b=bb;  }

       void  show( )

        {  System.out.println('a='+a+'\nb='+b);  }

    }

    class   SubClass   extends   SuperClass

    {  int c;

       SubClass(int  aa,int  bb,int  cc)

       {   super(aa,bb);

           c=cc;

       }

    }

   class   SubSubClass   extends   SubClass

   {   int  a;

       SubSubClass(int aa,int  bb,int  cc)

       {   super(aa,bb,cc);

           a=aa+bb+cc;

        }

       void  show()

        {  System.out.println('a='+a+'\nb='+b+'\nc='+c);  }

  }

  

4. import    java.io.*;

  public class abc

    {

         public static void main(String args[])

{

                String  s1 = 'Hello!';

                String  s2 = new String('World!');

                System.out.println(s1.concat(s2));

         }

     }

 

 

5.  import  java.io.* ;

public  class  ABC

  {

public  static  void   main(String  args[ ])

{  int   i  ;

         int  a[ ] = { 11,22,33,44,55,66,77,88,99 };

         for  ( i = 0 ; i <= a.length / 2 ; i ++ )

               System.out.print( a[i]+a[a.length-i-1]+'  ');

            System.out.println( );

}

    }

 

 

6. import  java.io.*;

class  Parent

{

      void  printMe()

      {

          System.out.println('parent');

      }

}

class  Child  extends Parent

{

      void  printMe()

      {

          System.out.println('child');

      }

      void  printAll()

      {

          super.printMe();

          this.printMe();

          printMe();

  }

}

 

public class  Class1

{

  public static void main(String  args[ ])

  {

       Child  myC = new  Child( );

     myC.printAll( );

  }

}