Dear Friends
I am trying to write a program to display a diamond pattern based on the user input size.
The output must like this below :
But when I wrote my Java program , it gives the out put belowPlease type an integer number: 4 ******** ***##*** **####** *######* *######* **####** ***##*** ********
And this is my Java program .Please type an integer number: 4 **** ***## **#### *###### **####### ***##### ****###
import java.util.Scanner; public class DiamondPattern2{ public static void main(String[] args){ Scanner keyboard = new Scanner(System.in); System.out.print("Please type an integer number: "); int n = keyboard.nextInt(); for (int i = 1; i <= n; i++){ System.out.print("*"); for (int j = 0; j < (n - i); j++) System.out.print("*"); for (int j = 2; j <= i; j++) System.out.print("#"); for (int k = 2; k < (i+1); k++) System.out.print("#"); System.out.println(); } for (int i = n - 1; i >= 1; i--){ System.out.print("*"); for (int j = 0; j < (n - i); j++) System.out.print("*"); for (int j = 0; j <= (i*2); j++) System.out.print("#"); for (int k = n; k <= (i); k++) System.out.print("#"); System.out.println(); } } }
I don't know how to continue to complete s on the other side and fix # . Anyone can fix my program ?
Thanks
Naif