Celebrate ๐Ÿ‡ฎ๐Ÿ‡ณ Republic Day Discount Upto 70% OFF + Extra 26% OFF โ€” One Coupon for All Courses โ†’ BHARAT26 Limited Time Offer   << Click Here >>

X Shape Star Pattern Program in Java  


Program:
*   *
 * *
  *
 * *
*   *
  • Program:
    public class StarPattern12
    {
        public static void main(String[] args)
        {
            for (int i=1; i<=5; i++)
            {
                for (int j=1; j<=5; j++)
                {
                    if (j==i || j==(5-i+1))
                    {
                        System.out.print("*");
                    }
                    else
                    {
                        System.out.print(" ");
                    }
                }
                System.out.println();
            }
        }
    }