E F G and H character pattern programs in Java
In this series of tutorial, we will study how to print character pattern programs in java. In this post, we will see how to create pattern E, F, G, and H in Java.
1. Character Pattern E in Java
In this program we learn how to print character pattern E using Java Programming language
import java.util.*; class E { public static void main(String[] args) { Scanner scan =new Scanner(System.in); System.out.println("Enter the value of n"); int n=scan.nextInt(); for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if((i==0||i==n-1||i==n/2)&&(j>0&&j<3*(n/4))||(i!=0&&i!=n-1)&&j==0) { System.out.print("*"); } else { System.out.print(" "); } } System.out.println(); } } }
Output of pattern E in java
Enter the value of n 8 ***** * * * ****** * * *****
2. Character Pattern F in Java
In this program we study how to display character pattern F using Java Programming language
import java.util.*; class F { public static void main(String[] args) { Scanner scan =new Scanner(System.in); System.out.println("Enter the value of n"); int n=scan.nextInt(); for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if((i==0||i==n/2)&&(j>0&&j<3*(n/4))||(i!=0)&&j==0) { System.out.print("*"); } else { System.out.print(" "); } } System.out.println(); } } }
Output of pattern F in java
Enter the value of n 8 ***** * * * ****** * * *
3. Character Pattern G in Java
In this program we learn how to display character pattern G using Java Programming language
import java.util.*; class G { public static void main(String[] args) { Scanner scan =new Scanner(System.in); System.out.println("Enter the value of n"); int n=scan.nextInt(); for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(i==0&&(j>0&&j<=3*(n/4))|| j==0&&(i>0&&i<n-1)|| i==n-1&&(j>0&&j<n/2)|| (j==n/2||j==3*(n/4))&&i>3*(n/4)|| i==3*(n/4)&&(j>=n/2&&j<=3*(n/4))) { System.out.print("*"); } else { System.out.print(" "); } } System.out.println(); } } }
Output of pattern G in java
Enter the value of n 8 ****** * * * * * * *** **** *
4. Character Pattern H in Java
In this program we study how to print character pattern H using Java Programming language
import java.util.*; class H { public static void main(String[] args) { Scanner scan =new Scanner(System.in); System.out.println("Enter the value of n"); int n=scan.nextInt(); for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(j==0||j==3*(n/4)||i==n/2&&j<3*(n/4))//if(j==0&&i<n/2||j==0&&i>n/2||j==3*(n/4)&&i<n/2||j==3*(n/4)&&i>n/2||j>0&&j<3*(n/4)&&i==n/2) { System.out.print("*"); } else { System.out.print(" "); } } System.out.println(); } } }
Output of pattern H in java
Enter the value of n 8 * * * * * * * * ******* * * * * * *
These series of articles deals with how to display character pattern programs in java, different diamond pattern programs printing in java, number pattern displaying programs in java, alphabet pattern programs in java, pattern programs in java with explanation, string pattern printing in programs in java, diamond number pattern programs in java, square pattern programs in java. These are the commonly asked pattern programs in many campus and off campus placement interviews.
If you find anything incorrect please contact us at click here. For regular updates and any suggestion please like facebook page