0
import java.util.Scanner;

public class Exam_Test {
	public static void main(String args[]) {

		Scanner input =new Scanner(System.in);
		int number;
		System.out.println(" Enter a Number : ");
		number = input.nextInt();
		
		
	
		
		for (int i = 0; i <= number; i+=2) 
		{

			for (int j = number; j >= i; j--)

			{
				System.out.print(" ");
			
				if (j == i) 
				{
					for (int d = 0; d <= i; d++) 
					{
						System.out.print(" ");
						System.out.print("*");
					}
				}
			}
			
			
			System.out.println("");
		}
		
		
		if (number %2==0)
			
		{
		
	
		for (int i = number - 2 ; i >= 0; i-=2) 
		
		{
			

			for (int j = number; j >= i; j--)

			{
				System.out.print(" ");
			
				if (j == i) 
				{
					for (int d = 0; d <= i; d++) 
					{
						System.out.print(" ");
						System.out.print("*");
					}
				}
			}
			
			
			System.out.println("");
		}
		}
		else
			
		{
			{
				
				
				for (int i = number - 3 ; i >= 0; i-=2) 
				
				{
					

					for (int j = number; j >= i; j--)

					{
						System.out.print(" ");
					
						if (j == i) 
						{
							for (int d = 0; d <= i; d++) 
							{
								System.out.print(" ");
								System.out.print("*");
							}
						}
					}
					
					
					System.out.println("");
				}
				}
		}
	}

}

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

2
Contributors
1
Reply
3
Views
7 Years
Discussion Span
Last Post by Grn Xtrm
0

You need to ask a question if you expect to get any help. Tell us specifically where you are encountering problems. Also, please use code tags to make the code more readable.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.