Home>

There are some points that I cannot understand with the code described in "Introduction to java that is clear".

(1) The (int size) that received the argument (3) in the main method
The reason why the description has changed to new int [size] in the next line.
(Why can I compile without problems even if new is added?)
(2) The reason why size is described as [size] in the description of new int [size].
Corresponding source code
public class Main {
  public static int [] makeArray (int size) {
    int [] newArray = new int [size];
    for (int i = 0;i<newArray.length;i ++) {
      newArray [i] = i;
    }
    return newArray;
  }
  public static void main (String [] args) {
    int [] array = makeArray (3);
    for (int i: array) {
      System.out.println (i);
    }
  }
}
What I tried

I read the reference book many times, but I couldn't understand it.
This is an unsightly question for beginners, but thank you.

Supplementary information (FW/tool version, etc.)

Please provide more detailed information here.