Alphabet F pattern in java
Steps to do this:-
1. take 3 integers i,j,n ( i and j is for loop and n is for user input length )2. take a length from user
3. start the i loop from (i=1;i<=n;i++) start the j loop inside i loop and from (j=1;j<=n;j++) now check
if(j==1 || i==1 || i==n/2)
{
print "*"
}
else
{
print " "
}
close the j loop and print a new line inside i loop
Explanation:-
when we check if (j==1) it will print the 1st coloumn
*
*
*
*
*
when we check if (i==1) it will print the 1st row
***********
when we check if (i==n/2) it will print the last row
***********
and the end of the loop it will print F
4.Save and run
The Source Code
import java.util.Scanner;
class fpattern
{
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int i,j,n;// i and j is for loop and n is for user input length
System.out.println("enter the length");
n=s.nextInt();
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(i==1||j==1||i==(n/2))
{
System.out.print("*");
}
else
{
System.out.print(" ");
}
}
System.out.println();
}
}
}
OUTPUT
Watch My Video
Comments
Post a Comment
if you like it or have any doubts please let me know