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!

I assume by

I got this program that supposed to display a diamond

you mean you copied some code out of the Internet for your assignment. Well, a homework assignment is for you to do, not copy. How do you expect to learn anything when you don't do anything.

If that's not the the case, apologies (and don't bother wasting your time professing that it isn't), but then you should probably choose some better wording next time.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.