1.判断下面的说法是否正确。如果错误,请说明原因

①一个数组中可以存放多个不同类型的值

②数组下标通常是 float 型的

③二维数组其实质是一维数组的一维数组

2.什么是异常?举出程序中常见的异常的种类?

3. 运行例题 6-1 到例题 6-10。

4. Java中异常处理有什么优点?

5.在 Java 中,throw 与 throws 有什么区别?它们各自用在什么地方?

6. try-catch-finally 语句的执行顺序是怎样的?

7.运行例题 6-11 到例题 6-14。

8. 看程序写结果。

(1)下面是一个排序的程序:

JAVA
import java.io.;

public class Test56_Sort{

public static void main(String args[ ]){

    int[] a={42,99,5,63,95,36,2,69,200,96};

    System.out.println("排序前的数据序列:");

    ShowArray(a);

    Sort(a);

    System.out.println("排序后的数据序列:");

    ShowArray(a);

}

public static void Sort(int[] x){

    int w;

    for(int i=1; i<x.length; i++){

        for(int j=0; j<x.length-1; j++)

            if(x[j]>x[j+1]){

w=x[j]; x[j]=x[j+1]; x[j+1]=w;

}

/ if(i==1||i==2) ShowArray(x);

if(i==2) break; /

}

}

public static void ShowArray(int b[]){

    for(int i=0; i<b.length; i++)

    System.out.print(" "+b[i]);

    System.out.println(" ");

}

}

问题: 如果将方法Sort( )中的一对注释符(/ */)去掉,程序输出的结果是什么?

(2)写出以下程序的功能

JAVA
public  class  ABC{

    public  static  void   main(String  args[ ]){

        int   i , j ;

        int  a[ ] = { 9,7,5,1,3};

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

            int  k = i;

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

                if  ( a[j]>a[k] )  k = j;

            int  temp =a[i];

            a[i] = a[k];

            a[k] = temp;       

}

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

            System.out.print(a[i]+"  ");

       System.out.println( );

    }

}

(3)仔细阅读下面的程序,写出程序的执行顺序(写出编号):

JAVA
public class UsingExceptions {

   public static void main( String args[] ) {

        try{       

         method1();                            // 1

       }catch(Exception e){

          System.err.println(e.getMessage());    // 2

       }

       finally{

          System.out.println("Program is end!");  // 3

       }

   }

   public static void method1() throws Exception {

      method2();                              //4

   }

   public static void method2() throws Exception {

      method3();                           //5

   }

   public static void method3() throws Exception {

      throw new Exception( "Exception thrown in method3" ); //6

   }

}

9. 写程序。

(1)将一个数组中的值按逆序重新存放。假定原来的顺序为 4,1,3,5,9,2,1。要求改为 1,2,9,5,3,1,4。
(2)写出比较 2 个字符串是否相同的方法,并加以说明。

评论