declaring array of string | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 9

declaring array of string

I am trying to declare array of strings like this String[] password = new String[7]; and i recieve this error Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7 at Program.main(Program.java:17) when i do the other way around String password[] = new String[7]; it still gives an error

9th Feb 2017, 4:10 PM
adeel salim
adeel salim - avatar
4 ответов
+ 10
no i am trying to save 8 strings in this array through a loop... but it gives error when i try to declare it
9th Feb 2017, 4:19 PM
adeel salim
adeel salim - avatar
+ 9
Thanks buddy it is working
9th Feb 2017, 4:42 PM
adeel salim
adeel salim - avatar
+ 1
Thats the problem the size of array is 7 and you cant store 8 string....at 8th string (7 time of loop) You are using password[7] variable which doesn't exist....!
9th Feb 2017, 4:29 PM
Shreyance Gupta
Shreyance Gupta - avatar
0
both are right...i think When you run the program You are forget that Index is from 0 so that last index is 6 not 7 .! for More Specify your question!
9th Feb 2017, 4:17 PM
Shreyance Gupta
Shreyance Gupta - avatar