I am trying to return a string so that it is not printed in the function but rather in the main class.
I have tried to concatenate the string on every character that comes out so that the string keeps growing depending on the inputted number.
public class Main {
public static void main(String[] args) {
Diamond print = new Diamond();
output = print.print(5);
System.out.print(output);
}
}
class Diamond {
public static String print(int n) {
String concat = "";
if(!(n % 2 == 0)) {
for (int i = 1; i < n; i += 2) {
for (int k = n; k >= i; k -= 2) {
System.out.print(" ");
concat = concat.(" ");//what i am trying to do :(
}
for (int j = 1; j <= i; j++) {
System.out.print("*");
concat = concat.("*");
}
concat = concat.("\n");
System.out.println();
}// end loop
for (int i = 1; i <= n; i += 2) {
for (int k = 1; k <= i; k += 2) {
System.out.print(" ");
}
for (int j = n; j >= i; j--) {
System.out.print("*");
}
System.out.println();
}// end loop
}
return concat;
}
}