Q R S T and U 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 Q, R, S, T and U in Java.
1. Character Pattern Q in Java
In this article we study how to display character pattern Q in Java programming language.
import java.util.*; class Q { 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==j&&i>=n/2||(i==0||i==3*(n/4))&&(j>0&&j<3*(n/4))||(j==0||j==3*(n/4))&&(i>0&&i<3*(n/4)))//if(i==j&&i>=n/2||j==0&&i>0&&i<n-1|| i==0&&j>0&&j<=3*(n/4)||j==n-2&&i>0&&i<=3*(n/4)||j>0&&j<=3*(n/4)&&i==n-2) { System.out.print("*"); } else { System.out.print(" "); } } System.out.println(); } } }
Output of pattern Q in java
Enter the value of n 8 ***** * * * * * * * * * * ** ****** *
2. Character Pattern R in Java
In this article we study how to print character pattern R in Java programming language.
import java.util.*; class R { 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&&i>=0||i==n/2&&j>=0||i==0&&j>=0||j==n-1&&i<=n/2||i>=sn/2&&i==j) { System.out.print("*"); } else { System.out.print(" "); } } System.out.println(); } } }
Output of pattern R in java
Enter the value of n 8 ******** ** * * * * * * * ******** * * * * * *
3. Character Pattern T in Java
In this article we demonstrate how to display character pattern T in Java programming language.
import java.util.*; class T { 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<=n||j==n/2&&i>=0) { System.out.print("*"); } else { System.out.print(" "); } } System.out.println(); } } }
Output of pattern T in java
Enter the value of n 8 ******** * * * * * * *
4. Character Pattern U in Java
In this article we demonstrate how to print character pattern U in Java programming language.
import java.util.*; class U { 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&&i>=0||i==n-1&&j>=0||j==n-1&&i>=0) { System.out.print("*"); } else { System.out.print(" "); } } System.out.println(); } } }
Output of pattern U in java
Enter the value of n 8 * * * * * * * * * * * * * * ********
These series of tutorial deals with how to display character pattern programs in java, printing different diamond pattern programs in java, number pattern programs in java, alphabet pattern programs in java, pattern programs in java with explanation, displaying string pattern programs in java, printing 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 please like the facebook page