I got this program that supposed to display a diamond but I only got the top part of diamond to work. As for bottom part I am not sure what calculation I could use. Any hint would be appreciated! Thanks
This is the part:
//Bottom Part
for ( row = 1; row <= num/2+1; row++ )
This is the actual code:
public class Diamond {
public static void main(String[] args)
{
String numInput, diamondString = "";
int num, row, spaces, stars;
numInput = JOptionPane.showInputDialog("Enter an odd number between 3 to 15:");
num = Integer.parseInt(numInput);
//this outer loop controls how many rows the top half of the diamond will have
for ( row = 1; row <= num/2+1; row++ )
{
//this first inner loop will control how many spaces you will need between each asterisk
for ( spaces = num; spaces > row; spaces-- )
{
diamondString += " " ;
}
//this inner loop will actually control how many asterisks to print
for ( stars = 1; stars <= ( 2 * row ) - 1; stars++ )
{
diamondString += "*" ;
}
diamondString += "\n" ;
}
//Bottom Part
for ( row = 1; row <= num/2+1; row++ )
{
//this first inner loop will control how many spaces you will need between each asterisk
for ( spaces = num; spaces > row; spaces-- )
{
diamondString += " " ;
}
//this inner loop will actually control how many asterisks to print
for ( stars = 1; stars <= ( 2 * row ) - 1; stars++ )
{
diamondString += "*" ;
}
diamondString += "\n" ;
}
System.out.println(diamondString);
}
}
Thanks!