I am new to java and still learning, so keep that in mind. I am trying to write a program in which the user can enter a keyword, and he converts it into numbers and puts in an array. My problem is that the array should keep repeating int.
My code is:
String keyword=inputdata.nextLine(); int[] key = new int[keyword.length()]; for (int k = 0; k < keyword.length(); ++k) { if (keyword.charAt(k) >= 'a' && keyword.charAt(k) <= 'z') { key[k]= (int)keyword.charAt(k) - (int)'a'; } }
Right now, if I try to get any key[i] higher than keyword.length , it throws an outofbounds error. I need it to be small.
Basically, if keyword.length() was 3, I need to be able to see that key[2] matches key[5] and key[8] , etc.
Thank you for your help!
java arrays loops
Giant dwarf
source share