Showing posts with label Java program for 'F'. Show all posts
Showing posts with label Java program for 'F'. Show all posts

Java program for the pattern of 'F' | Patterns in JAVA | JAVA POINT

 

Java Program for F



Ques - Write a java program for the following pattern of 'F' :


* * * *    

*     

*     

* * * * 

*      

*     


PROGRAM :


import java.util.Scanner;
public class PatternF
{
    public static void main(String[] args)
    {
        System.out.print("Enter the number of rows : ");

        Scanner scan=new Scanner(System.in);

        System.out.println();

        int n=scan.nextInt();

        for (int i=0;i<n ;i++ )
        {
            for (int j=0;j<=n/2 ;j++ )
            {
                if (i==0||i==n/2||j==0)
                {
                    System.out.print("* ");
                }
                else
                {
                    System.out.print("  ");
                }
            }
            System.out.println();
        }
    }
}


/*

Output:

Enter the number of rows : 7


* * * * 

*         

*                 

* * * * 

*         

*         

*         

*/


Related post:

Java codes for pattern design of alphabet 'G'