I got this assignment in Java and I don't have a single clue on how to do it.
The task is to receive an integer n > 0, and to print n number of frames constructed by *
inside each other, while the inner frame will have the letter "X" constructed by 4n+1 *
.
I can't use arrays or strings.
For example: n=1 will print:
*******
* *
* * * *
* * *
* * * *
* *
*******
n=2 will print:
*************
* *
* ********* *
* * * *
* * * * * *
* * * * * *
* * * * *
* * * * * *
* * * * * *
* * * *
* ********* *
* *
*************
This is what I have so far:
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int size = n * 6 + 1;
int x = 1;
int y = 1;
for (int i = 0; i < n; i = i + 1) {
for (int i3 = 0; i3 < size; i3 = i3 + 1) {
System.out.print("*");
}
System.out.println("");
y = y + 1;
for (int i1 = 0; i1 < size - 2; i1 = i1 + 1) {
System.out.print("*");
for (int i2 = 0; i2 < size - 2; i2 = i2 + 1) {
System.out.print(" ");
}
System.out.println("*");
y = y + 1;
}
for (int i4 = 0; i4 < size; i4 = i4 + 1) {
System.out.print("*");
}
}