I am trying to reverse this code so that I can print a diamond shape with a border around it. What is the best way to begin reversing a nested loop/series of loops? I tried tinkering around with the code but everything comes out jumbled and out of order. Any advice?
Also, is there a way to make an even number of .'s on each side of the stars at the top? The only way I have been able to make it work prints an even amount on each side by one...
Here is what should be printed to the console: https://i.stack.imgur.com/SyYzp.jpg
Here is my code:
public class SixTester {
public static void main(String[] args)
{
int i,j,k;
int numOfRows = 8; // Made this a variable, so that the program can make any size diamond (try playing around with different values eg. 2 or 16)
// Step 1. The first Dash
for(i=0;i<numOfRows*2 +2;i++)
System.out.print(" "); // Number of spaces is double the number of rows in your 'Half Pyramid'
System.out.println("-");
// Step 2. The First half diamond
for (j=0; j<numOfRows ; j++ )
{
for(k=numOfRows*2; k>1+j*2; k--)
System.out.print(" ");
System.out.print("_/");
for (i=0; i< 2+j*4; i++)
{
// Prepare the Star rectangle, Note that it starts half the way (rows/2)
if(j >= numOfRows/2 && (i>j*2- numOfRows/2 && i<j*2+ numOfRows/2)) {
System.out.print("*");
}
else
System.out.print(".");
}
System.out.println("\\_");
}
// Next Step - Make the bottom pyramid...but how to reverse?
}
}