In: Computer Science
5.24 (Diamond Printing Program) Write an application that prints the following diamond shape. You may use output statements that print a single asterisk (*), a single space or a single new- line character. Maximize your use of repetition (with nested for statements), and minimize the number of output statements."
Example for 2.24:
   *
***
*****
*******
*********
*******
*****
***
*
import java.util.Scanner;
public class PrintDiamond {
   public static void main(String[] args) {
       Scanner sc = new
Scanner(System.in);
       System.out.println("Enter N :
");
       int n = sc.nextInt();
       // printing the first half
       for (int i = 1; i <= n; i+=2)
{
           for (int j = 1;
j <= i; j++) {
          
    System.out.print("*");
           }
          
System.out.println();
       }
       // printing the second half
       for (int i = n - 1; i >=0; i-=2)
{
           for (int j = 1;
j <= i; j++) {
          
    System.out.print("*");
           }
          
System.out.println();
       }
   }
}
