Hallow Triangles

     /*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication1;
import java.util.*;

/**
 *
 * @author Basit
 */
public class JavaApplication1 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        System.out.println("Salam Pakistan");
        Scanner input = new Scanner(System.in);
        System.out.print("Plz Enter a number :");
        int num = input.nextInt();
     
 
       
        for ( int i=1 ; i<=num; i++ ) {
         for ( int j=1 ; j <= i ; j++ ) {
            if(i==1 || i==2 || i==num || j==1 || j==i)
              System.out.print("*");
            else
              System.out.print(" ");
         }
         System.out.println();
      }
       
             for ( int i=num ; i>=1; i-- ) {
           {
         for ( int j=1 ; j <= i ; j++ ) {
            if(i==1 || i==2 || i==num || j==1 || j==i)
              System.out.print("*");
            else
              System.out.print(" ");
         }
         System.out.println();
      }
     
       
       }
   
   
    }
}

Comments