public static void reverse(String[] array){
String reverse = "";
for(int i=0;i<array.length;i++){
for(int j = array[i].length() - 1; j >= 0; i--)
{
reverse = reverse + array[i].charAt(i);
}
}
}
Using this method I am trying to reverse every single string in the string array but it just throws an exception. The array's length and elements are being inputed with scanner.
public static String[] arrayStringCreation(String[] array){
boolean isArrayInputStillGoing = true;
while (isArrayInputStillGoing){
System.out.println();
System.out.println("Input the size of the array");
int sizeOfArray = scanner.nextInt();
if (sizeOfArray <= 0){
System.err.println("Size can't be less than 1");
continue;
}
array = new String[sizeOfArray+1];
System.out.println("Input words less than 20 symbols");
for(int i=0;i<sizeOfArray+1;i++){
array[i] = scanner.nextLine();
if (array[i].length()>20){
System.err.println("Try again with a word with less than 20 symbols");
i--;
}
}
isArrayInputStillGoing=false;
}
return array;
}
array[i].charAt(j)? Also, you're never resetting reverse to""chartype in Java is obsolete. Use code point numbers instead.