0

Java error array index out of bond

When try get value from command line argument https://code.sololearn.com/cDUc211U512u/?ref=app

9th Jul 2019, 6:46 AM
DedpOol
5 Respostas
+ 3
It seems that codes running on Code Playground was ran without any command line argument passed, when I checked `args.length` it yields zero, the `args` array is empty.
9th Jul 2019, 7:22 AM
Ipang
+ 2
Do a check for `args.length` before tempting to get an element out of it, if the length yields non zero, then proceed with parsing a value (int) from it, probably using a try ... catch block just in case the number parsing failed. I'm not sure how fault tolerant `Integer.ParseInt` is, so please take care on that part.
9th Jul 2019, 7:27 AM
Ipang
+ 1
How solve it
9th Jul 2019, 7:23 AM
DedpOol
+ 1
I don't think you can pass any runtime arguments when you run code on Sololearn. The alternative is to ask for user input via Scanner object.
9th Jul 2019, 9:12 AM
Tibor Santa
Tibor Santa - avatar
+ 1
Thank u
10th Jul 2019, 6:16 AM
DedpOol