I need to have the program printout the attached image.
I already have the code for all of it but the diamond in the center as follows:
The first question would be if there is any way to reduce and simplify that code, but using nothing more advanced than "for" loops.
Secondly, I am stuck on the diamond part. Using a for loop, I get stuck with the following code:
Any help is appreciated, and thanks in advance.
I already have the code for all of it but the diamond in the center as follows:
Code:
public class threes {
public static void main( String[] args )
{
int rows, columns;
for (rows=1; rows<=1; rows++)
{
for (columns=1; columns<=36; columns++)
{
System.out.print("*");
}
System.out.print("\n");
}
for (rows=1; rows<=6; rows++)
{
{
System.out.print("***");
}
System.out.print(" ");
}
System.out.print("\n");
for (rows=1; rows<=6; rows++)
{
{
System.out.print("***");
}
System.out.print(" ");
}
System.out.print("\n");
for (rows=1; rows<=6; rows++)
{
{
System.out.print(" ");
}
System.out.print("***");
}
System.out.print("\n");
for (rows=1; rows<=6; rows++)
{
{
System.out.print(" ");
}
System.out.print("***");
}
System.out.print("\n");
for (rows=1; rows<=1; rows++)
{
for (columns=1; columns<=36; columns++)
{
System.out.print("*");
}
System.out.print("\n");
}
System.out.print("\n");// END OF FIRST SECTION
// DIAMOND SHAPE
for (rows=1; rows<=1; rows++)// START OF SECOND SECTION
{
for (columns=1; columns<=36; columns++)
{
System.out.print("*");
}
System.out.print("\n");
}
for (rows=1; rows<=6; rows++)
{
{
System.out.print(" ");
}
System.out.print("***");
}
System.out.print("\n");
for (rows=1; rows<=6; rows++)
{
{
System.out.print(" ");
}
System.out.print("***");
}
System.out.print("\n");
for (rows=1; rows<=6; rows++)
{
{
System.out.print("***");
}
System.out.print(" ");
}
System.out.print("\n");
for (rows=1; rows<=6; rows++)
{
{
System.out.print("***");
}
System.out.print(" ");
}
System.out.print("\n");
for (rows=1; rows<=1; rows++)
{
for (columns=1; columns<=36; columns++)
{
System.out.print("*");
}
System.out.print("\n");
}
System.exit( 0 );
} // end main
} // end of program
The first question would be if there is any way to reduce and simplify that code, but using nothing more advanced than "for" loops.
Secondly, I am stuck on the diamond part. Using a for loop, I get stuck with the following code:
Code:
// third nested for loop ... what is the output here?
public class diamond {
public static void main( String[] args )
{
int rows, columns;
for (rows=1; rows<=3; rows++)
{
for (columns=1; columns < rows; columns++)
{
System.out.print(" ");
}
System.out.print("*\n");
}
System.out.print("\n");
System.exit( 0 );
} // end main
} // end of program
Any help is appreciated, and thanks in advance.