Question: Write a Java program to display the following pattern. You have to take a number that is odd
number.
Solution:
package pattern.pkg01; import java.util.Scanner; public class Pattern01 { public static void main(String[] args) { Scanner obj = new Scanner(System.in); System.out.print("Enter you value: "); int n = obj.nextInt(); for(int i=0;i<n;i++){ for(int k=n-i;k<n;k++){ System.out.print(" "); } for(int j=i;j<n;j++){ System.out.print("*"); } System.out.println(""); } for(int i=2;i<=n;i++){ for(int k=i+1;k<=n;k++){ System.out.print(" "); } for(int j=1;j<=i;j++){ System.out.print("*"); } System.out.println(""); } } }