arrayreturn.java

来自「程序练习中包括书中实例程序代码和练习中要用到的代码,是压缩文件」· Java 代码 · 共 30 行

JAVA
30
字号
package examples.basic;

/** A method demonstrating how arrays can be a
  * return type
  */
public class ArrayReturn {
   /** A method that returns an array object
     * @param flag A boolean value for which
     *             array to return
     * @returns An integer array object
     */
   public int[] returnsArray( boolean flag ) {
      int[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
      int[] array2 = { 10, 20, 30, 40, 50 };
      if ( flag ) {
         return array1;
      } else {
         return array2;
      }
   }

   /** The test method for the class
     * @param args Not used
     */
   public static void main( String[] args ) {
      ArrayReturn x = new ArrayReturn();
      System.out.println( x.returnsArray( true ).length );
      System.out.println( x.returnsArray( false ).length );
   }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?