⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lineswithdifflength.java

📁 Java the UML Way 书中所有源码
💻 JAVA
字号:
/*
 * LinesWithDiffLength.java   E.L. 2001-08-14
 *
 */
class LinesWithDiffLength {
  public static void main(String[] args) {
    /* An array where all the lines may be of different length. */
    int[][] myArray = new int[3][];   // second index is not given

    /* We create three small arrays, which represent the lines */
    myArray[0] = new int[5];
    myArray[1] = new int[4];
    myArray[2] = new int[2];

    /*
     * We put test values into the array, one line at a time.
     * The length of line no. i is given by myArray[i].length
     */
    for (int i = 0; i < myArray[0].length; i++) myArray[0][i] = i;
    for (int i = 0; i < myArray[1].length; i++) myArray[1][i] = i;
    for (int i = 0; i < myArray[2].length; i++) myArray[2][i] = i;

    /* We print the lines. */
    for (int i = 0; i < myArray.length; i++) {  // myArray.length is equal to the no. of lines
      System.out.print("The length of line: " + myArray[i].length + " Data: ");
      for (int j = 0; j < myArray[i].length; j++) System.out.print(myArray[i][j] + " ");
      System.out.println();
    }
  }
}

/* Example Run:

The length of line: 5 Data: 0 1 2 3 4
The length of line: 4 Data: 0 1 2 3
The length of line: 2 Data: 0 1
*/

⌨️ 快捷键说明

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