Following are the Patterns asked in many job interviews for both Freshers as well as Experience. Same logic will apply to all the programming languages.
Write a Program to Print the following Pattern
import java.util.Scanner; public class PatternOne { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter the size:"); int input = sc.nextInt(); for(int i = 0; i < input; i++) { for(int j = 0; j < input; j++) { System.out.print("*"); } System.out.println(); } sc.close(); } }
Write a Program to Print the following Pattern
import java.util.Scanner; public class PatternTwo { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter the size:"); int input = sc.nextInt(); for(int i = 0; i <= input; i++) { for(int j = 0; j < i; j++) { System.out.print("*"); } System.out.println(); } sc.close(); } }
Write a Program to Print the following Pattern
import java.util.Scanner; public class PatternThree { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter the size:"); int input = sc.nextInt(); for (int i = 0; i < input; i++) { for (int j = input; j > i; j--) { System.out.print("*"); } System.out.println(); } sc.close(); } }
Write a Program to Print the following Pattern
import java.util.Scanner; public class PatternFour { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter the size:"); int input = sc.nextInt(); for(int i = 0; i < input; i++) { for(int j = input-1; j >= 0; j--) { if(j > i) { System.out.print(" "); }else { System.out.print("*"); } } System.out.println(); } sc.close(); } }
Write a Program to Print the following Pattern
import java.util.Scanner; public class PatternFive { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter the size:"); int input = sc.nextInt(); for(int i = 0; i < input; i++) { for(int j = 0; j < input; j++) { if(j >= i) { System.out.print("*"); }else { System.out.print(" "); } } System.out.println(); } sc.close(); } }
Write a Program to Print the following Pattern
import java.util.Scanner; public class PatternSix { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter the size:"); int input = sc.nextInt(); for(int i = 0; i < input; i++) { for(int j = input-1; j >= 0; j--) { if(j > i) { System.out.print(" "); }else { System.out.print("* "); } } System.out.println(); } sc.close(); } }
Write a Program to Print the following Pattern
import java.util.Scanner; public class PatternSeven { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter the size:"); int input = sc.nextInt(); for(int i = 0; i < input; i++) { for(int j = 0; j < input; j++) { if(j >= i) { System.out.print("* "); }else { System.out.print(" "); } } System.out.println(); } sc.close(); } }
Write a Program to Print the following Pattern
import java.util.Scanner; public class PatternEight { public static void main(String[] args) { int min_stars = 0; Scanner sc = new Scanner(System.in); System.out.println("Enter the size:"); int input = sc.nextInt(); int space = input - 1; for (int i = 0; i < input; i++) { for (int j = space; j > i; j--) { System.out.print(" "); } for (int k = 0; k <= min_stars; k++) { System.out.print("*"); } min_stars += 2; System.out.println(); } sc.close(); } }
Write a Program to Print the following Pattern
import java.util.Scanner; public class PatternNine { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter the size:"); int input = sc.nextInt(); int odd = 1; int noOfSpaces = input / 2; for (int i = 1; i <= input; i++) { for (int k = noOfSpaces; k >= 1; k--) { System.out.print(" "); } for (int j = 1; j <= odd; j++) { System.out.print("*"); } System.out.println(); if(i < input / 2+1) { odd = odd + 1; noOfSpaces--; } else { odd = odd - 1; noOfSpaces++; } } sc.close(); } }
Write a Program to Print the following Pattern
import java.util.Scanner; public class PatternTen { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter the size:"); int input = sc.nextInt(); int odd = 1; for (int i = 1; i <= input; i++) { for (int j = 1; j <= odd; j++) { System.out.print("*"); } System.out.println(); if (i < input / 2+1) { odd = odd + 1; } else{ odd = odd - 1; } } sc.close(); } }
Write a Program to Print the following Pattern
import java.util.Scanner; public class PatternEleven { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter the size:"); int input = sc.nextInt(); int odd = 1; int noOfSpaces = input / 2+1; for (int i = 1; i <= input; i++) { for (int k = noOfSpaces; k >= 1; k--) { System.out.print(" "); } for (int j = 1; j <= odd; j++) { System.out.print("*"); } System.out.println(); if(i < input/2+1) { odd = odd + 2; noOfSpaces--; } else { odd = odd - 2; noOfSpaces++; } } sc.close(); } }
Write a Program to Print the following Alphabet Pattern
public class AlphabetsPatternOne { public static void main(String args[]) { for (char i = 'A'; i <= 'E'; i++) { for (char j = 'A'; j <= 'E'; j++) { System.out.print(i); } System.out.println(); } } }
Write a Program to Print the following Alphabet Pattern
public class AlphabetsPatternTwo { public static void main(String args[]) { for (char i = 'A'; i <= 'E'; i++) { for (char j = 'A'; j <= 'E'; j++) { System.out.print(j); } System.out.println(); } } }
Write a Program to Print the following Alphabet Pattern
public class AlphabetsPatternThree { public static void main(String args[]) { for (char i = 'E'; i >= 'A'; i--) { for (char j = 'E'; j >= 'A'; j--) { System.out.print(i); } System.out.println(); } } }
Write a Program to Print the following Alphabet Pattern
public class AlphabetsPatternFour { public static void main(String args[]) { for (char i = 'E'; i >= 'A'; i--) { for (char j = 'E'; j >= 'A'; j--) { System.out.print(j); } System.out.println(); } } }
Write a Program to Print the following Alphabet Pattern
public class AlphabetsPatternFive { public static void main(String args[]) { for (char i = 'A'; i <= 'E'; i++) { for (char j = 'A'; j <= i; j++) { System.out.print(i); } System.out.println(""); } } }
Write a Program to Print the following Pattern
public class AlphabetsPatternSix { public static void main(String args[]) { for (char i = 'A'; i <= 'E'; i++) { for (char j = 'A'; j <= i; j++) { System.out.print(j); } System.out.println(""); } } }
Write a Program to Print the following Alphabet Pattern
public class AlphabetsPatternSeven { public static void main(String args[]) { for (int i = 0; i <= 5; i++) { for (int j = 5; j > i; j--) { System.out.print((char) (i + 65)); } System.out.println(""); } } }
Write a Program to Print the following Alphabet Pattern
public class AlphabetsPatternEight { public static void main(String args[]) { for (int i = 5; i > 0; i--) { for (int j = 0; j < i; j++) { System.out.print((char) (j + 65)); } System.out.println(""); } } }
Write a Program to Print the following Alphabet Pattern
public class AlphabetsPatternNine { public static void main(String args[]) { for (int i = 4; i >= 0; i--) { for (int j = 0; j <= i; j++) { System.out.print((char) (i + 65)); } System.out.println(""); } } }
Write a Program to Print the following Alphabet Pattern
public class AlphabetsPatternTen { public static void main(String args[]) { for (int i = 0; i < 5; i++) { for (int j = 4; j >= i; j--) { System.out.print((char) (j + 65)); } System.out.println(""); } } }
Write a Program to Print the following Alphabet Pattern
public class AlphabetsPatternEleven { public static void main(String args[]) { int n = 5; int a = 1; for (int i = 0; i < n; i++) { for (int j = n - 1; j > i; j--) { System.out.print(" "); } for (int k = 1; k <= a; k++) { System.out.print((char) (i + 65)); } a++; System.out.println(""); } } }
Write a Program to Print the following Alphabet Pattern
public class AlphabetsPatternTwelve { public static void main(String args[]) { int n = 5; int a = 1; for (int i = 0; i < n; i++) { for (int j = n - 1; j > i; j--) { System.out.print(" "); } for (int k = 0; k < a; k++) { System.out.print((char) (k + 65)); } a++; System.out.println(""); } } }
Write a Program to Print the following Alphabet Pattern
public class AlphabetsPatternThirteen { public static void main(String args[]) { int n = 5; int a = 5; for (int i = n - 1; i >= 0; i--) { for (int j = n - 1; j > i; j--) { System.out.print(" "); } for (int k = 0; k < a; k++) { System.out.print((char) (i + 65)); } a--; System.out.println(""); } } }
Write a Program to Print the following Alphabet Pattern
public class AlphabetsPatternFourteen { public static void main(String args[]) { int n = 5; int a = 5; for (int i = 1; i <= n; i++) { for (int j = 1; j < i; j++) { System.out.print(" "); } for (int k = 0; k < a; k++) { System.out.print((char) (k + 65)); } a--; System.out.println(""); } } }
Write a Program to Print the following Alphabet Pattern
public class AlphabetsPatternFifteen { public static void main(String args[]) { int m = 1; int height = 5; int space = height - 1; for (int i = 0; i <= height; i++) { for (int j = space; j > i; j--) { System.out.print(" "); } for (int k = 0; k < m; k++) { System.out.print((char) (i + 65)); } m += 2; System.out.println(""); } } }
Write a Program to Print the following Alphabet Pattern
public class AlphabetsPatternSixteen { public static void main(String args[]) { int m = 0; int height = 5; int space = height - 1; for (int i = 0; i <= height; i++) { for (int j = space; j > i; j--) { System.out.print(" "); } for (int k = 0; k <= m; k++) { System.out.print((char) (m + 65)); } m += 2; System.out.println(""); } } }
Write a Program to Print the following Alphabet Pattern
public class AlphabetsPatternSeventeen { public static void main(String args[]) { int m = 0; int height = 5; int space = height - 1; for (int i = 0; i <= height; i++) { for (int j = space; j > i; j--) { System.out.print(" "); } for (int k = 0; k <= m; k++) { System.out.print((char) (k + 65)); } m += 2; System.out.println(""); } } }
Write a Program to Print the following Alphabet Pattern
public class AlphabetsPatternEighteen { public static void main(String args[]) { int n = 5; int a = 0; for (int i = 0; i <= n; i++) { for (int j = n - 1; j > i; j--) { System.out.print(" "); } for (int k = 0; k <= a; k++) { System.out.print((char) (a - k + 65)); } a += 2; System.out.println(""); } } }
Write a Program to Print the following Alphabet Pattern
public class AlphabetsPatternNinteen { public static void main(String args[]) { int n = 5; int a = 1; int l = 1; for (int i = 0; i < 5; i++) { for (int j = 4; j > i; j--) { System.out.print(" "); } for (int k = 1; k <= a; k++) { System.out.print((char) (Math.abs(k - l) + 65)); } l++; a += 2; System.out.println(""); } } }
Write a Program to Print the following Alphabet Pattern
public class AlphabetsPatternTwenty { public static void main(String args[]) { int n = 5; int a = 1; for (int i = 0; i < 5; i++) { for (int j = n - 1; j >= i; j--) { System.out.print(" "); } for (int k = i; k >= -i; k--) { System.out.print((char) (i - Math.abs(k) + 65)); } a += 2; System.out.println(""); } } }
Write a Program to Print the following Alphabet Pattern
public class AlphabetsPatternTwentyOne { public static void main(String args[]) { int width = 7; int space = width / 2; int height = width - space; for (int i = height - 1; i >= 0; i--) { for (int j = space; j >= i; j--) { System.out.print(" "); } for (int k = 1; k <= width; k++) { System.out.print((char) (i + 65)); } width -= 2; System.out.println(""); } } }
Write a Program to Print the following Alphabet Pattern
public class AlphabetsPatternTwentyTwo { public static void main(String args[]) { int width = 7; int space = width / 2; int height = width - space; for (int i = height; i >= 1; i--) { for (int j = space; j >= i; j--) { System.out.print(" "); } for (int k = 1; k <= width; k++) { System.out.print((char) ((width - 1) + 65)); } width -= 2; System.out.println(""); } } }
Write a Program to Print the following Alphabet Pattern
public class AlphabetsPatternTwentyThree { public static void main(String args[]) { int width = 7; int space = width / 2; int height = width - space; for (int i = height; i >= 1; i--) { for (int j = space; j >= i; j--) { System.out.print(" "); } for (int k = 0; k < width; k++) { System.out.print((char) (k + 65)); } width -= 2; System.out.println(""); } } }
Write a Program to Print the following Alphabet Pattern
public class AlphabetsPatternTwentyFour { public static void main(String args[]) { int size = 3; for (int i = size; i >= -size; i--) { for (int j = size; j >= Math.abs(i); j--) { System.out.print((char) (j + 65)); } System.out.println(""); } } }
Write a Program to Print the following Alphabet Pattern
public class AlphabetsPatternTwentyFive { public static void main(String args[]) { int size = 3; for (int i = size; i >= -size; i--) { for (int j = Math.abs(i); j <= size; j++) { System.out.print((char) (j + 65)); } System.out.println(""); } } }
Write a Program to Print the following Number Pattern
public class NumberPatternOne { public static void main(String args[]) { for (int i = 1; i <= 5; i++) { for (int j = 1; j <= 5; j++) { System.out.print(i); } System.out.println(); } } }
Write a Program to Print the following Number Pattern
public class NumberPatternTwo { public static void main(String args[]) { for (int i = 1; i <= 5; i++) { for (int j = 1; j <= 5; j++) { System.out.print(j); } System.out.println(); } } }
Write a Program to Print the following Number Pattern
public class NumberPatternThree { public static void main(String args[]) { for (int i = 5; i >= 1; i--) { for (int j = 1; j <= 5; j++) { System.out.print(i); } System.out.println(); } } }
Write a Program to Print the following Number Pattern
public class NumberPatternFour { public static void main(String args[]) { for (int i = 5; i >= 1; i--) { for (int j = 5; j >= 1; j--) { System.out.print(j); } System.out.println(" "); } } }
Write a Program to Print the following Number Pattern
public class NumberPatternFive { public static void main(String args[]) { for (int i = 1; i <= 5; i++) { for (int j = 1; j <= i; j++) { System.out.print(i); } System.out.println(" "); } } }
Write a Program to Print the following Number Pattern
public class NumberPatternSix { public static void main(String args[]) { for (int i = 1; i <= 5; i++) { for (int j = 1; j <= i; j++) { System.out.print(j); } System.out.println(" "); } } }
Write a Program to Print the following Number Pattern
public class NumberPatternSeven { public static void main(String args[]) { for (int i = 1; i <= 5; i++) { for (int j = 5; j >= i; j--) { System.out.print(i); } System.out.println(" "); } } }
Write a Program to Print the following Number Pattern
public class NumberPatternEight { public static void main(String args[]) { for (int i = 5; i >= 1; i--) { for (int j = 1; j <= i; j++) { System.out.print(j); } System.out.println(); } } }
Write a Program to Print the following Number Pattern
public class NumberPatternNine { public static void main(String args[]) { for (int i = 5; i >= 1; i--) { for (int j = 1; j <= i; j++) { System.out.print(i); } System.out.println(); } } }
Write a Program to Print the following Number Pattern
public class NumberPatternTen { public static void main(String args[]) { for (int i = 1; i <= 5; i++) { for (int j = 5; j >= i; j--) { System.out.print(j); } System.out.println(); } } }
Write a Program to Print the following Number Pattern
public class NumberPatternEleven { public static void main(String args[]) { int n = 5; int a = 1; for (int i = 1; i <= n; i++) { for (int j = n - 1; j >= i; j--) { System.out.print(" "); } for (int k = 1; k <= a; k++) { System.out.print(i); } a++; System.out.println(); } } }
Write a Program to Print the following Number Pattern
public class NumberPatternTwelve { public static void main(String args[]) { int n = 5; int a = 1; for (int i = 1; i <= n; i++) { for (int j = n - 1; j >= i; j--) { System.out.print(" "); } for (int k = 1; k <= a; k++) { System.out.print(k); } a++; System.out.println(); } } }
Write a Program to Print the following Number Pattern
public class NumberPatternThirteen { public static void main(String args[]) { int n = 5; int a = 5; for (int i = n; i >= 1; i--) { for (int j = 5; j > i; j--) { System.out.print(" "); } for (int k = 1; k <= a; k++) { System.out.print(i); } a--; System.out.println(); } } }
Write a Program to Print the following Number Pattern
public class NumberPatternFourteen { public static void main(String args[]) { int n = 5; int a = 5; for (int i = n; i >= 1; i--) { for (int j = 5; j > i; j--) { System.out.print(" "); } for (int k = 1; k <= a; k++) { System.out.print(k); } a--; System.out.println(); } } }
Write a Program to Print the following Number Pattern
public class NumberPatternFifteen { public static void main(String args[]) { int n = 3; int i; int j; for (i = n; i >= -n; i--) { for (j = n; j >= Math.abs(i); j--) { System.out.print(j); } System.out.println(" "); } } }
Write a Program to Print the following Number Pattern
public class NumberPatternSixteen { public static void main(String args[]) { int n = 5; int z = 1; for (int i = 0; i < n; i++) { for (int j = n - 1; j > i; j--) { System.out.print(" "); } for (int k = 0; k < z; k++) { System.out.print(z - i); } z += 2; System.out.println(); } } }
Write a Program to Print the following Number Pattern
public class NumberPatternSeventeen { public static void main(String args[]) { int n = 5; int z = 1; for (int i = 0; i < n; i++) { for (int j = n - 1; j > i; j--) { System.out.print(" "); } for (int k = 0; k < z; k++) { System.out.print(z); } z += 2; System.out.println(); } } }
Write a Program to Print the following Number Pattern
public class NumberPatternEighteen { public static void main(String args[]) { int n = 5; int z = 1; for (int i = 0; i < n; i++) { for (int j = n - 1; j > i; j--) { System.out.print(" "); } for (int k = 1; k <= z; k++) { System.out.print(k); } z += 2; System.out.println(); } } }
Write a Program to Print the following Number Pattern
public class NumberPatternNinteen { public static void main(String args[]) { int n = 5; int z = 1; for (int i = 0; i < n; i++) { for (int j = n - 1; j > i; j--) { System.out.print(" "); } for (int k = 0; k < z; k++) { System.out.print(z - k); } z += 2; System.out.println(); } } }
Write a Program to Print the following Number Pattern
public class NumberPatternTwenty { public static void main(String args[]) { int n = 4; int z = 1; for (int i = 1; i <= n; i++) { for (int j = n - 1; j >= i; j--) { System.out.print(" "); } for (int k = i - 1; k >= -(i - 1); k--) { System.out.print(i - Math.abs(k)); } z += 2; System.out.println(); } } }
Write a Program to Print the following Number Pattern
public class NumberPatternTwentyOne { public static void main(String args[]) { int n = 9; int space = n / 2; int height = n - space; for (int i = height; i >= 1; i--) { for (int j = space; j >= i; j--) { System.out.print(" "); } for (int k = 1; k <= n; k++) { System.out.print(k); } n -= 2; System.out.println(); } } }
Write a Program to Print the following Number Pattern
public class NumberPatternTwentyTwo { public static void main(String args[]) { int n = 9; int space = n / 2; int height = n - space; for (int i = height; i >= 1; i--) { for (int j = space; j >= i; j--) { System.out.print(" "); } for (int k = 1; k <= n; k++) { System.out.print(i); } n -= 2; System.out.println(); } } }
Write a Program to Print the following Number Pattern
public class NumberPatternTwentyThree { public static void main(String args[]) { int n = 9; int space = n / 2; int height = n - space; for (int i = height; i >= 1; i--) { for (int j = space; j >= i; j--) { System.out.print(" "); } for (int k = 1; k <= n; k++) { System.out.print(n); } n -= 2; System.out.println(); } } }
Write a Program to Print the following Number Pattern
public class NumberPatternTwentyFour { public static void main(String args[]) { int n = 3; int i; int j; for (i = n; i >= -n; i--) { for (j = Math.abs(i); j <= n; j++) { System.out.print(j); } System.out.println(" "); } } }
Write a Program to Print the following Number Pattern
public class NumberPatternTwentyFive { public static void main(String args[]) { int n = 3; int i; int j; int k; for (i = n; i >= -n; i--) { for (j = 1; j <= Math.abs(i); j++) { System.out.print(" "); } for (k = n; k >= Math.abs(i); k--) { System.out.print(k); } System.out.println(); } } }
Write a Program to Print the following Number Pattern
public class NumberPatternTwentySix { public static void main(String args[]) { int n = 3; int i; int j; int k; for (i = n; i >= -n; i--) { for (j = 1; j <= Math.abs(i); j++) { System.out.print(" "); } for (k = Math.abs(i); k <= n; k++) { System.out.print(k); } System.out.println(); } } }
Write a Program to Print the following Number Pattern
public class NumberPatternTwentySeven { public static void main(String args[]) { int i; int j; int k; for (i = 1; i <= 5; i++) { for (j = 4; j >= i; j--) { System.out.print(" "); } for (k = 1; k <= i; k++) { System.out.print(i + " "); } System.out.println(); } } }
Write a Program to Print the following Number Pattern
public class NumberPatternTwentyEight { public static void main(String args[]) { int i; int j; int k; for (i = 1; i <= 5; i++) { for (j = 4; j >= i; j--) { System.out.print(" "); } for (k = 1; k <= i; k++) { System.out.print(k + " "); } System.out.println(); } } }
Write a Program to Print the following Number Pattern
public class NumberPatternTwentyNine { public static void main(String args[]) { int height = 5; int i; int j; int k; for (i = height; i >= 1; i--) { for (j = height - 1; j >= i; j--) { System.out.print(" "); } for (k = i; k >= 1; k--) { System.out.print(i + " "); } System.out.println(); } } }
Write a Program to Print the following Number Pattern
public class NumberPatternThirty { public static void main(String args[]) { int height = 5; int i; int j; int k; for (i = height; i >= 1; i--) { for (j = height - 1; j >= i; j--) { System.out.print(" "); } for (k = i; k >= 1; k--) { System.out.print(k + " "); } System.out.println(); } } }
Write a menu driven program to do the task according to user’s choice:
2: 1 * 3 * 5
* 3 * 5 *
3* 5 * 7
*5 * 7 *
5 *7 * 9
plz solve this problem sir as soon as possiable
#include
int main()
{
int temp1,i,j,k1,n,temp2,k2;
printf(“Enter:”);
scanf(“%d”,&n);
k1=1;
k2=3;
for(i=1;i<=n;i++)
{
if(i%2!=0)
{
temp1=k1;
for(j=1;j<=n;j++)
{
if(j%2!=0)
{
printf("%d ",temp1);
temp1+=2;
}
else
{
printf("* ");
}
}
k1+=2;
}
else
{
temp2=k2;
for(j=1;j<=n;j++)
{
if(j%2!=0)
{
printf("* ");
}
else
{
printf("%d ",temp2);
temp2+=2;
}
}
k2+=2;
}
printf("\n");
}
return 0;
}
A
B A
C B A
D C B A
E D C B A
PLEASE DO THIS …
How to do both number and alphabet pattern
Example:
1 2 A
1 A B
A B C
how to display this pattern….?!!
A
2 C
4 E 6
How to print this pattern?
1
1A1
1B1B1
1C1C1C1
1D1D1D1D1
c
* b
* a
*
please solve this pattern,
2
4 6
8 10 12
14 16
18
Regards
Can you display
J
J A
J A V
J A V A
Please do
1
3 2
6 5 4
10 9 8 7
15 14 13 12 11
Can you display
A
* *
A B C
* * * *
A B C D E
Please solve this pattern : Where user inputed row is 5.
A
B*B
C*A*C
D*B*B*D
E*C*A*C*E
D*B*B*D
C*A*C
B*B
A