The code should know what the length of the input is, which is a string. For example, if "apple" is put in, it displays
EDIT NEW ANSWER
row 1: APPL
row 2: E***
EDIT row 3: (***) should not be here
If Water Melon
Row 1: Wate
Row 2: r Me
Row 3: lon*
EDIT (Row 4: ****) should not be here
It finds the minimum 1 by 1, 2 by 2, 3 by 3 and so forth length possible. Spaces are included, and extra spaces are replaced with asterisks
The code below runs perfectly if there is an assigned length for the 2D array. I need a way for the array to dynamically change based on the string input
public A(String input) {
// Array = new String[4][4];
int i = 0;
// Increment through the rows
for (int row = 0; row < Array.length; row++) {
// Increment through the columns
for (int col = 0; col < Array[0].length; col++) {
if (i < input.length() && (row * col) <= input.length()) {
Array[row][col] = input.substring(i, i + 1);
i++;
} else
Array[row][col] = " ";
}
}
}
A test = new A("Apple");
System.out.println(test);
A test2 = new A("Water Melon");
System.out.println(test2);
ArrayList. Also, a sidenote - I think instead of increment, you mean iterate.