You're supposed to run this code through the command line. Example:
java ClassName 0 4 7 12 55
Java will know the length because it has an array of input values: 0 4 7 12 55
. This array is the same as String[] args
passed into the main
method.
If you want to learn more about command line arguments, then I'd recommend this source.
Note: there are some IDEs that handle command line arguments for you.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…