# Java patterns

Java Alphabet Pattern

Pattern 1 :: Inupt integer n from stdin and then draw the pattern according to it.
For example if you enter 5 then, the pattern should be like this

A
B C
D E F
G H I  J
K L M N O

Solution:-

import java.util.Scanner;
public class Pattern1 {
public static void main(String[] args){
int alphabet = 65,n;
Scanner scn=new Scanner(System.in);
System.out.println(“Enter the Input value ::”);
n=scn.nextInt();
for (int i = 0; i <= n; i++){
for (int j = 1; j <= i; j++){
System.out.print((char) alphabet + ” “);
alphabet++;
}
System.out.println();
}
}
}

Pattern 2 :: Inupt integer n from stdin and then draw the pattern according to it.
For example if you enter 5 then, the pattern should be like this

A
A B A
A B C B A
A B C D C B A
A B C D E D C B A

Solution:-

import java.io.*;

import java.util.*;

public class Pattern2{
public static void main(String args[] ) throws Exception {

int n,c,i,j,k;
System.out.println(“Enter the Input value ::”);
for(i=1;i<=n;i++){

c=64+i;
for(j=i;j<n;j++){

System.out.print(” “+” “);

}
for(k=1;k<=2*i-1;k++){
int a=64+k;
if(k<=i){
System.out.print((char)a);
if(k<2*i-1){
System.out.print(” “);
}
}
else{

System.out.print((char)–c);
if(k<2*i-1){
System.out.print(” “);

}
}
}
System.out.println();
}

}

}

Pattern 3 :: Inupt integer n from stdin and then draw the pattern according to it.
For example if you enter 4 then, the pattern should be like this

E D C B A
E D C B
E D C
E D
E

Solution:-

import java.util.Scanner;
public class Pattern3{
public static void main(String args[] ) throws Exception {
int alphabet = 65,i,j;
Scanner scn=new Scanner(System.in);
System.out.println(“Enter the Input value ::”);
int n=scn.nextInt();
for (i = 0; i <=n; i++){
for (j = n; j >= i; j–){
System.out.print((char)(alphabet + j)+” “);
}
System.out.print(“\n”);
}
}
}

Pattern 4 :: Inupt integer n from stdin and then draw the pattern according to it.
For example if you enter 4 then, the pattern should be like this

A
A  B
A  B  C
A  B  C  D

Solution:-

import java.util.Scanner;

public class Pattern4{
public static void main(String[] args){
int n,i,j,k;
int alphabet = 65;
Scanner scn=new Scanner(System.in);
System.out.println(“Enter the Input value ::”);
n=scn.nextInt();
for (i = 0; i <= n; i++){
for ( j = n; j >=i; j–){
System.out.print(” “);
}

for (k = 0; k <= i-1; k++){
System.out.print((char) (alphabet + k) + ” “);
}
System.out.println();
}
}
}

Pattern 5 :: Inupt integer n from stdin and then draw the pattern according to it.
For example if you enter 7 then, the pattern should be like this

A  B  C  D  E  F  G
B  C  D  E  F  G
C  D  E  F  G
D  E  F  G
E  F  G
F  G
G

Solution:-

import java.util.Scanner;
public class Pattern5{
public static void main(String[] args){
int n,alphabet = 65,i,j,k;
Scanner scn=new Scanner(System.in);
System.out.println(“Enter the Input value ::”);
n=scn.nextInt();
for (i = 0; i <n; i++){
for (j = 0; j < i; j++){
System.out.print(” “);
}
for (k = i; k <n; k++){
System.out.print((char) (alphabet + k) + ” “);
}
System.out.println();
}
}
}

Pattern 6 :: Inupt integer n from stdin and then draw the pattern according to it.
For example if you enter 6 then, the pattern should be like this

A  A   A  A  A  A
A  A   A  A  A  B
A  A   A  A  C  C
A  A   A  D  D  D
A  A   E  E  E   E
A  F   F   F  F   F
G  G  G  G  G  G

Solution:-

import java.util.Scanner;
public class Pattern6{
public static void main(String[] args){
int n, alphabet = 65,i,j,k;
Scanner scn=new Scanner(System.in);
System.out.println(“Enter the Input value ::”);
n=scn.nextInt();
for ( i = 0; i <= n; i++){
for ( j = n; j > i; j–){
System.out.print(‘A’ + ” “);
}

for (k = 0; k <i; k++){
System.out.print((char) (alphabet + i) + ” “);
}
System.out.println();
}
}
}

Pattern 7 :: Inupt the String which needs to be printed from stdin and then draw the pattern
according to it. For example if you enter INDIA then, the pattern should be like this

I
N  N  N
D  D  D D  D
I  I   I   I  I   I  I   I
A  A  A  A  A  A  A  A A

Solution:-

import java.util.Scanner;
public class Pattern7{
public static void main(String[] args){
String input;
int i,j,k;
Scanner scn = new Scanner(System.in);
System.out.println(“Enter the String which needs to be printed “);
input = scn.nextLine();
for (i = 1; i <= input.length(); i++) {
for (j = input.length(); j > i; j–){
System.out.print(” “);
}
for (k = i * 2 – 1; k >= 1; k–){
System.out.print(input.charAt(i – 1));
}
System.out.println(“”);
}

}
}

Pattern 8 :: Inupt integer n from stdin and then draw the pattern according to it.
For example if you enter 7 then, the pattern should be like this
A
B  B
C  C  C
D  D  D D
E  E   E  E  E
F   F  F   F   F  F
G  G  G  G  G  G  G

Solution:-

import java.util.Scanner;
public class Pattern8{
public static void main(String[] args){
int n, i,j,k,alphabet = 65;
Scanner scn = new Scanner(System.in);
System.out.println(“Enter the Input Value ::”);
n = scn.nextInt();
for (i = 0; i <n; i++){
for (j = n; j > i; j–){
System.out.print(” “);
}
for (k = 0; k <= i; k++){
System.out.print((char) (alphabet + i) + ” “);
}
System.out.println();
}
}
}

Pattern 9 :: Inupt integer n from stdin and then draw the pattern according to it.
For example if you enter 5 then, the pattern should be like this

E
D  D
C  C  C
B  B  B  B
A  A  A  A  A

Solution:-

package com.nt.CoreProgram;

import java.util.Scanner;

public class Pattern9{
public static void main(String[] args){
int n, i,j,k,alphabet = 65;
Scanner scn = new Scanner(System.in);
System.out.println(“Enter the Input Value ::”);
n = scn.nextInt();
for (i = n; i >=0; i–){
for (j = 0; j < i; j++){
System.out.print(” “);
}
for (k = i; k <n; k++){
System.out.print((char) (alphabet + i) + ” “);
}
System.out.println();
}
}
}

Pattern 10 :: Inupt integer n from stdin and then draw the pattern according to it.
For example if you enter 4 then, the pattern should be like this

A  B  C  D  E
B  C  D  E
C  D  E
D  E
E
E
D  E
C  D  E
B  C  D  E
A  B  C  D  E

Solution:-

import java.util.Scanner;

public class Pattern10{
public static void main(String[] args) {
int n, i,j,k,alphabet = 65;
Scanner scn = new Scanner(System.in);
System.out.println(“Enter the Input Value ::”);
n = scn.nextInt();
for (i = 0; i <= n; i++){
for (j = 0; j < i; j++){
System.out.print(” “);
}
for (k = i; k <= n; k++){
System.out.print((char) (alphabet + k) + ” “);
}
System.out.println();
}
for (i = n; i >= 0; i–){
for (j = 0; j < i; j++){
System.out.print(” “);
}
for (k = i; k <= n; k++){
System.out.print((char) (alphabet + k) + ” “);
}
System.out.println();
}
}
}

Pattern 11 :: Inupt integer n from stdin and then draw the pattern according to it.
For example if you enter 7 then, the pattern should be like this

A
A  B
A  B  C
A  B  C  D
A  B  C  D  E
A  B  C  D  E  F
A  B  C  D  E  F  G
A  B  C  D  E  F  G  H
A  B  C  D  E  F  G
A  B  C  D  E  F
A  B  C  D  E
A  B  C  D
A  B  C
A  B
A

Solution:-

import java.util.Scanner;

public class Pattern11{
public static void main(String[] args){
int n, i,j,k,alphabet = 65;
Scanner scn = new Scanner(System.in);
System.out.println(“Enter the Input Value ::”);
n = scn.nextInt();
for (i = 0; i <=n; i++){
for (j = n; j >= i; j–){
System.out.print(” “);
}
for (k = 0; k <= i; k++){
System.out.print((char) (alphabet + k) + ” “);
}
System.out.println();
}
for (i = 0; i <=n; i++){
for (j = -1; j <= i; j++){
System.out.print(” “);
}
for (k = 0; k <= (n-1) – i; k++){
System.out.print((char) (alphabet + k) + ” “);
}
System.out.println();
}
}
}

Pattern 12 :: Inupt integer n from stdin and then draw the pattern according to it.
For example if you enter 4 then, the pattern should be like this

A
A   B
A  B  C
A  B  C  D
A  B  C  D
A  B  C
A  B
A

Solution:-

import java.util.Scanner;

public class Pattern12{
public static void main(String[] args){
int n, i,j,k,alphabet = 65;
Scanner scn = new Scanner(System.in);
System.out.println(“Enter the Input Value ::”);
n = scn.nextInt();
for (i = 0; i <n; i++){
for (j = n; j >= i; j–){
System.out.print(” “);
}
for (k = 0; k <= i; k++){
System.out.print((char) (alphabet + k) + ” “);
}
System.out.println();
}
for (i = 0; i <n; i++){
for (j = -1; j <= i; j++){
System.out.print(” “);
}
for (k = 0; k <= (n-1) – i; k++){
System.out.print((char) (alphabet + k) + ” “);
}
System.out.println();
}
}
}

Pattern 13 :: Inupt Charectur from stdin and then draw the pattern according to it.
For example if you enter G then, the pattern should be like this

A
B       B
C            C
D                D
E                    E
F                          F
G                             G
F                          F
E                    E
D               D
C         C
B    B
A

Solution:-

import java.util.Scanner;

public class Pattren13 {
public static void main(String[] args) {
char[] ch = { ‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘F’, ‘G’, ‘H’, ‘I’, ‘J’,
‘K’, ‘L’, ‘M’, ‘N’, ‘O’, ‘P’, ‘Q’, ‘R’, ‘S’, ‘T’, ‘U’, ‘V’,
‘W’, ‘X’, ‘Y’, ‘Z’ };
int ch_number = 0;
String[] s = new String[26];
System.out.print(“Enter a Char between A to Z : “);
Scanner scn = new Scanner(System.in);
try {
char user_letter = scn.next(“[A-Z]”).charAt(0);
// search for charecture number in the array charecture
for (int i = 0; i < ch.length; i++) {
if (ch[i] == user_letter) {
ch_number = i;
break;
}
}
for (int i = 0; i <= ch_number; i++) {
s[i] = “”;
for (int j = 0; j < ch_number – i; j++) {
s[i] += ” “;
}

s[i] += ch[i];

if (ch[i] != ‘A’) {
for (int j = 0; j < 2 * i – 1; j++) {
s[i] += ” “;
}
s[i] += ch[i];
}
// Draw the first part.
System.out.println(s[i]);
}

for (int i = ch_number – 1; i >= 0; i–){
// Draw the second part and Writing the Array in reverse order.
System.out.println(s[i]);
}
}
catch (Exception e){
e.printStackTrace();
}
finally{
scn.close();
}
}
}

Pattern 14 :: Inupt integer n from stdin and then draw the pattern according to it.
For example if you enter 7 then, the pattern should be like this

A
B B
C C C
D D D D
E E  E E  E
F F  F F  F F
G G G G G G G

Solution:-

import java.util.Scanner;

public class Pattren14{
public static void main(String[] args) {
int n;
char ch = ‘A’;
Scanner scn=new Scanner(System.in);
System.out.println(“Enter the number :”);
n=scn.nextInt();
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(ch);
}
ch++;
System.out.println();
}
}
}

Pattern 15 :: Inupt integer n from stdin and then draw the pattern according to it.
For example if you enter 7 then, the pattern should be like this

A
A B
A B C
A B C D
A B C D E
A B C D E F
A B C D E F G
A B C D E F
A B C D E
A B C D
A B C
A B
A

Solution:-

import java.util.Scanner;

public class Pattren15{
public static void main(String[] args) {
int n,i,j,ch=65;
Scanner scn=new Scanner(System.in);
System.out.println(“Enter the number :”);
n=scn.nextInt();
for (i = 0; i <n; i++){
for (j = 0; j <= i; j++){
System.out.print((char) (ch + j) + ” “);
}
System.out.println();
}
for (i = n; i >0; i–){
for (j = 0; j < i – 1; j++){
System.out.print((char) (ch + j) + ” “);
}
System.out.println();
}
}
}

Java Star Pattern

Pattern 1 :: Inupt integer n from stdin and then draw the pattern according to it.
For example if you enter 10 then, the pattern should be like this

**********
*********
********
*******
******
*****
****
***
**
*
**
***
****
*****
******
*******
********
*********
**********

Solution:-

import java.util.Scanner;
public class Pattern1 {
public static void main(String[] args) {
int n;
Scanner scn=new Scanner(System.in);
System.out.println(“Enter the Input value ::”);
n=scn.nextInt();
for (int i = n; i >= 1; i–) {
for (int j = 1; j <= i; j++) {
System.out.print(“*”);
}
System.out.println();
}
for (int i = 2; i <= n; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(“*”);
}
System.out.println();
}
}

}

Pattern 2 :: Inupt integer n from stdin and then draw the pattern according to it.
For example if you enter 8 then, the pattern should be like this

* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *

Solution:-

import java.util.Scanner;
public class Prettan2 {
public static void main(String args[] ) throws Exception {                                               Scanner sc = new Scanner(System.in);
System.out.println(“Enter the Input value ::”);
int n = sc.nextInt();
for(int i = 1; i <= n; i++){
for(int j = 1; j <= 5 ;j++){
System.out.print(“*”);
if(j!=5){
System.out.print(” “);
}
}
System.out.println();
}
}
}

Pattern 3 :: Inupt integer n from stdin and then draw the pattern according to it.
For example if you enter 7 then, the pattern should be like this

*
***
*****
*******
*********
***********
*************

Solution:-

import java.util.Scanner;

public class pattren3{
public static void main(String[] args) {
int n = 0,k,i,j;
int count=n-1;
Scanner scn=new Scanner(System.in);
System.out.println(“Enter the number :”);
n=scn.nextInt();
for (k = 1; k <= n; k++) {
for (i = 1; i <= count; i++){
System.out.print(” “);
}
count–;
for (i = 1; i <= 2 * k – 1; i++){
System.out.print(“*”);
}
System.out.println();
}
}
}

Pattern 4 :: Inupt integer n from stdin and then draw the pattern according to it.
For example if you enter 9 then, the pattern should be like this

*********
********
*******
******
*****
****
***
**
*

Solution:

import java.util.Scanner;

public class Pattern4{
public static void main(String[] args) {
int n,i,j;
Scanner scn=new Scanner(System.in);
System.out.println(“Enter the value : “);
n=scn.nextInt();
for (i = n; i>= 1; –i) {
for (j = 1; j<= i; ++j) {
System.out.print(“*”);
}

System.out.println();
}
}
}

Pattern 5 :: Inupt integer n from stdin and then draw the pattern according to it.
For example if you enter 5 then, the pattern should be like this
*
***
*****
*******
*********

Solution:-

import java.util.Scanner;

public class Pattern5{
public static void main(String[] args) {
int n,i,k;
int count;
Scanner scn=new Scanner(System.in);
System.out.println(“Enter the value : “);
n=scn.nextInt();
count=n-1;
for (k = 1; k <= n; k++) {
for (i = 1; i <= count; i++){
System.out.print(” “);
}
count–;
for (i = 1; i <= 2 * k – 1; i++){
System.out.print(“*”);
}
System.out.println();
}
}
}

Pattern 5 :: Inupt integer n from stdin and then draw the pattern according to it.
For example if you enter 8 then, the pattern should be like this

*
***
*****
*******
*********
***********
*************
***************
*************
***********
*********
*******
*****
***
*

Solution:-

import java.util.Scanner;

public class Pattern5{
public static void main(String[] args) {
int n,i,k;
int count;
Scanner scn=new Scanner(System.in);
System.out.println(“Enter the value : “);
n=scn.nextInt();
count=n-1;
for (k = 1; k <= n; k++) {
for (i = 1; i <= count; i++){
System.out.print(” “);
}
count–;
for (i = 1; i <= 2 * k – 1; i++){
System.out.print(“*”);
}
System.out.println();
}
count = 1;
for (k = 1; k <= n – 1; k++) {
for (i = 1; i <= count; i++){
System.out.print(” “);
}
count++;
for (i = 1; i <= 2 * (n – k) – 1; i++){
System.out.print(“*”);
}
System.out.println();
}
}
}

Java Number Pattern

Pattern 1 :: Inupt integer n from stdin and then draw the pattern according to it.
For example if you enter 4 then, the pattern should be like this

1
2*3
4*5*6
7*8*9*10

Solution:-

import java.util.Scanner;

public class Number_Star_Pattern{
public static void main(String[] args) {
int n,i,j, a=1;
Scanner scn=new Scanner(System.in);
System.out.println(“Enetr the value :”);
n=scn.nextInt();
for(i=1;i<=n;i++){
for(j=1;j<i;j++){
System.out.print((a++)+”*”);
}
System.out.println(a++);
}
}
}

Pattern 2 :: Inupt integer n from stdin and then draw the pattern according to it.
For example if you enter 5 then, the pattern should be like this

1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5

Solution:-

import java.util.Scanner;

public class Prettan{
public static void main(String args[] ) throws Exception {
int n;
Scanner scn=new Scanner(System.in);
System.out.println(“Enetr the value :”);
n=scn.nextInt();
for(int i=1;i<=n;i++){
for(int j = 1; j <= n ;j++){
System.out.print(i+” “);
}
System.out.printf(“\n”);
}
}
}

Pattern 3 :: Inupt integer n from stdin and then draw the pattern according to it.
For example if you enter 5 then, the pattern should be like this

9 9 9 9 9 9 9 9 9
7 7 7 7 7 7 7
5 5 5 5 5
3 3 3
1

Solution:-

import java.util.Scanner;

public class Pattern3{
public static void main(String[] args) {
int i,j,s=10,n=0;
Scanner scn = new Scanner(System.in);
System.out.println(“Enter the Input Value ::”);
n = scn.nextInt();
for (i = n; i >= 1; i=i-2) {
for(j=1;j<=s;j++){
System.out.print(” “);
}
s=s+2;
for (j = 1; j <= i; j++) {
System.out.print(i);
System.out.print(” “);
}
System.out.println();
}
}
}

Pattern 4 :: Inupt integer n from stdin and then draw the pattern according to it.
For example if you enter 5 then, the pattern should be like this

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

Solution:-

import java.util.Scanner;

public class Pattern4{
public static void main(String[] args){
int n, i,j;
Scanner scn = new Scanner(System.in);
System.out.println(“Enter the Input Value ::”);
n = scn.nextInt();
for (i = 1; i <=n; i++){
for (j = 1; j<=i; j++){
System.out.print(j+” “);
}
System.out.println();
}
}
}

Pattern 5 :: Inupt integer n from stdin and then draw the pattern according to it.
For example if you enter 5 then, the pattern should be like this

1
1 1
1 1 1
1 1 1 1
1 1 1 1 1

Solution:-

import java.util.Scanner;

public class Pattern5{
public static void main(String[] args){
int n,i,j;
Scanner scn = new Scanner(System.in);
System.out.println(“Enter the Input Value ::”);
n = scn.nextInt();
for (i = 1; i <=n; i++){
for (j = 1; j<=i; j++){
System.out.print(“1″+” “);
}
System.out.println();
}
}
}

Pattern 6 :: Inupt integer n from stdin and then draw the pattern according to it.
For example if you enter 7 then, the pattern should be like this

1
12
123
1234
12345
123456
1234567

Solution:-

import java.util.Scanner;

public class Pattern6{
public static void main(String[] args) {
int n,i,j,s;
Scanner scn = new Scanner(System.in);
System.out.println(“Enter the Input Value ::”);
n = scn.nextInt();
s=n;
for(i = 1; i <=n; i++){
for(j = 1; j<=s; j++){
System.out.print(” “);
}
s–;
for(j=1;j<=i;j++){
System.out.print(j);
}
System.out.println();
}

}
}

Pattern 7 :: Inupt integer n from stdin and then draw the pattern according to it.
For example if you enter 4 then, the pattern should be like this

1
2  3
4  5  6
7  8  9 10

Solution:-

import java.util.Scanner;

public class Pattern7{
public static void main(String[] args) {
int n,i,j,s,k=1;
Scanner scn = new Scanner(System.in);
System.out.println(“Enter the Input Value ::”);
n = scn.nextInt();
s=n-1;
for (i = 1; i <=n; i++){
for (j = 1; j<=s; j++){
System.out.print(” “);
}
s–;
for(j=1;j<=i;j++){
System.out.print(k+” “);
k++;
}
System.out.println();
}
}
}

Pattern 8 :: Inupt integer n from stdin and then draw the pattern according to it.
For example if you enter 8 then, the pattern should be like this

1
1   1
1    2   1
1    3     3   1
1   4      6    4   1
1   5    10   10   5   1
1   6   15   20   15   6   1
1   7   21   35   35   21  7   1

Solution:-

import java.util.Scanner;

public class Pattern11 {
public static void main(String[] args) {
int n,no,i,j;
Scanner scn=new Scanner(System.in);
System.out.println(“Enter the value : “);
n=scn.nextInt();
for (i = 0; i < n; i++) {
no=1;
System.out.printf(“%” + (n – i) * 2 + “s”, “”);
for (j = 0; j <= i; j++) {
System.out.printf(“%4d”, no);
no = no * (i – j) / (j + 1);
}
System.out.println();
}
}
}

Pattern 9 :: Inupt integer n from stdin and then draw the pattern according to it.
For example if you enter 7 then, the pattern should be like this

1
212
32123
4321234
543212345
65432123456
7654321234567

Solution:-

import java.util.Scanner;

public class Pattern9 {
public static void main(String[] args) {
int n,no,i,j;
Scanner scn=new Scanner(System.in);
System.out.println(“Enter the value : “);
n=scn.nextInt();
for ( i = 1; i <= n; i++){
for (j = 1; j <= n – i; j++){
System.out.print(” “);
}
for (int k = i; k >= 1; k–){
System.out.print(k);
}
for (int l = 2; l <= i; l++){
System.out.print(l);
}
System.out.println();
}
}
}

Pattern 10 :: Inupt integer n from stdin and then draw the pattern according to it.
For example if you enter 4 then, the pattern should be like this

1
1 2
1 2 3
1 2 3 4
1 2 3
1 2
1

Solution:-

import java.util.Scanner;

public class Pattern10{
public static void main(String[] args) {
int n,no,i,j;
Scanner scn=new Scanner(System.in);
System.out.println(“Enter the value : “);
n=scn.nextInt();
for (i = 1; i < n; i++){
for (j = 1; j <= i; j++){
System.out.print(j+” “);
}
System.out.println();
}
for (i = n; i >= 0; i–) {
for (j = 1; j <= i; j++){
System.out.print(j+” “);
}
System.out.println();
}
System.out.println();
}
}

Pattern 11 :: Inupt integer n from stdin and then draw the pattern according to it.
For example if you enter 8 then, the pattern should be like this

1
1  2
1  2  3
1  2  3  4
1  2  3  4  5
1  2  3  4  5  6
1  2  3  4  5  6  7
1  2  3  4  5  6  7  8
1  2  3  4  5  6  7
1  2  3  4  5  6
1  2  3  4  5
1  2  3  4
1  2  3
1  2
1

Solution:-

import java.util.Scanner;

public class Pattern14{
public static void main(String[] args) {
int n,k,i,j;
Scanner scn=new Scanner(System.in);
System.out.println(“Enter the value : “);
n=scn.nextInt();
for (i = 1; i <= n; i++){
for (j = 1; j <= n – i; j++){
System.out.print(” “);
}
for (k = 1; k <= i; k++){
System.out.print(k + ” “);
}
System.out.println();
}
for (i = 1; i <= n-1; i++) {
for (j = 1; j <= i; j++){
System.out.print(” “);
}
for (k = 1; k <= n – i; k++){
System.out.print(k + ” “);
}
System.out.println();
}
}
}

Pattern 12 :: Inupt integer n from stdin and then draw the pattern according to it.
For example if you enter 8 then, the pattern should be like this

1 2 3 4 5 6 7 8
2 3 4 5 6 7 8
3 4 5 6 7 8
4 5 6 7 8
5 6 7 8
6 7 8
7 8
8
7 8
6 7 8
5 6 7 8
4 5 6 7 8
3 4 5 6 7 8
2 3 4 5 6 7 8
1 2 3 4 5 6 7 8

Solution:-

import java.util.Scanner;

public class Pattern12{
public static void main(String[] args) {
int n,k,i,j;
Scanner scn=new Scanner(System.in);
System.out.println(“Enter the value : “);
n=scn.nextInt();
for (i = 1; i <= n; i++) {
for (j = i; j <= n; j++) {
System.out.print(j+” “);
}
System.out.println();
}
for (i = n-1; i >= 1; i–) {
for (j = i; j <= n; j++){
System.out.print(j+” “);
}
System.out.println();
}
}
}

Pattern 13 :: Inupt integer n from stdin and then draw the pattern according to it.
For example if you enter 5 then, the pattern should be like this

1  2  3  4  5
2  3  4  5
3  4  5
4  5
5
4  5
3  4  5
2  3  4  5
1  2  3  4  5

Solution:-

import java.util.Scanner;

public class Pattern13{
public static void main(String[] args) {
int n,k,i,j;
Scanner scn=new Scanner(System.in);
System.out.println(“Enter the value : “);
n=scn.nextInt();
for ( i = 1; i <= n; i++){
for (j = 1; j < i; j++){
System.out.print(” “);
}
for (k = i; k <= n; k++){
System.out.print(k+” “);
}
System.out.println();
}
for (i = n-1; i >= 1; i–){
for (j = 1; j < i; j++){
System.out.print(” “);
}
for (k = i; k <= n; k++){
System.out.print(k+” “);
}
System.out.println();
}
}
}

Pattern 14 :: Inupt integer n from stdin and then draw the pattern according to it.
For example if you enter 6 then, the pattern should be like this

6 6 6 6 6 6
5 5 5 5 5 5
4 4 4 4 4 4
3 3 3 3 3 3
2 2 2 2 2 2
1 1 1 1 1 1

Solution:-

import java.util.Scanner;
public class Pattern14{
public static void main(String[] args) {
int n,i,j;
Scanner scn=new Scanner(System.in);
System.out.println(“Enter the value : “);
n=scn.nextInt();
for ( i = n; i >=1; i–){
for (j = 1; j <=n; j++){
System.out.print(i+” ” );
}
System.out.println();
}
}
}

Pattern 15 :: Inupt integer n from stdin and then draw the pattern according to it.
For example if you enter 8 then, the pattern should be like this

8 7 6 5 4 3 2 1
8 7 6 5 4 3 2
8 7 6 5 4 3
8 7 6 5 4
8 7 6 5
8 7 6
8 7
8
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8

Solution:-

import java.util.Scanner;

public class Pattern15{
public static void main(String[] args) {
int n,i,j;
Scanner scn=new Scanner(System.in);
System.out.println(“Enter the value : “);
n=scn.nextInt();
for ( i = 1; i <=n; i++){
for (j = n; j >=i; j–){
System.out.print(j+” ” );
}
System.out.println();
}
for ( i = 2; i <=n; i++){
for (j = 1; j <=i; j++){
System.out.print(j+” ” );
}
System.out.println();
}
}
}