If you are student or java programmer you will learn how to solve java pattern problems here we post many java pattern problems solution that help to you in this days many exams tells java patterns problems and what is good solution of patterns if you conduct an interview of java programer than it help you .java pattern problems check your java programming abilities.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
/**
*
* @author rajesh kumar shukla
*/
public class pattern12 {
public static void printNums(int n)
{
int i, j,num;
for(i=0; i<n; i++)
{
num=1;
for(j=0; j<=i; j++)
{
System.out.print(num+ " ");
num++;
}
System.out.println();
}
}
public static void main(String args[])
{
int n = 5;
printNums(n);
}
}
out put
run:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
========================================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
/**
*
* @author rajesh kumar shukla
*/
public class pattern13 {
public static void printNums(int n)
{
int i, j, num=1;
for(i=0; i<n; i++)
{
for(j=0; j<=i; j++)
{
System.out.print(num+ " ");
num = num + 1;
}
System.out.println();
}
}
public static void main(String args[])
{
int n = 5;
printNums(n);
}
}
out put
run:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
========================================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
/**
*
* @author rajesh kumar shukla
*/
public class pattern14 {
public static void main(String[] args) {
char ch = 'A';
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(ch);
ch++;
}
System.out.println();
}
}
}
out put
run:
A
BC
DEF
GHIJ
KLMNO
========================================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
/**
*
* @author rajesh kumar shukla
*/
public class pattern15 {
public static void main(String[] args)
{
int n = 5;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j < i; j++)
{
System.out.print(" ");
}
for (int k = i; k <= n; k++)
{
System.out.print(k+" ");
}
System.out.println();
}
for (int i = n-1; i >= 1; i--)
{
for (int j = 1; j < i; j++)
{
System.out.print(" ");
}
for (int k = i; k <= n; k++)
{
System.out.print(k+" ");
}
System.out.println();
}
}
}
out put
run:
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
========================================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
/**
*
* @author rajesh kumar shukla
*/
public class pattern16 {
public static void main(String[] args)
{
int n = 5;
for (int i = 1; i <= n; i++)
{
for (int j = i; j <= n; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
for (int i = n-1; i >= 1; i--)
{
for (int j = i; j <= n; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
}
}
out put
run:
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
========================================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
/**
*
* @author rajesh kumar shukla
*/
public class pattern17 {
public static void main(String[] args) {
int i, j, k;
int n = 5;
for (i = 1; i <= n; i++) {
for (j = 1; j <= i; ++j)
System.out.print(j);
for (k = n - i; k >= 1; k--)
System.out.print("*");
System.out.println();
}
}
}
out put
run:
1****
12***
123**
1234*
12345
========================================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
/**
*
* @author rajesh kumar shukla
*/
public class pattern18 {
public static void main(String[] args) {
int i = 5;
while (i >= 1) {
int j = 5;
while (j >= i) {
System.out.print(j);
j--;
}
i--;
System.out.println();
}
}
}
out put
run:
5
54
543
5432
54321
========================================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
/**
*
* @author rajesh kumar shukla
*/
public class pattern19 {
public static void main(String[] args) {
int n= 5;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n - i; j++) {
System.out.print(" ");
}
for (int k = 1; k <= i; k++) {
System.out.print(k + " ");
}
System.out.println("");
}
}
}
out put
run:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
========================================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
/**
*
* @author rajesh kumar shukla
*/
public class pattern20 {
public static void main(String []args){
char ch = 'A';
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(ch);
}
ch++;
System.out.println();
}
}
}
out put
run:
A
BB
CCC
DDDD
EEEEE
=======================================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
/**
*
* @author rajesh kumar shukla
*/
public class pattern21 {
public static void main(String[] args) {
int n, p, q;
n = 5;
for (int i = 1; i <= n; i++)
{
if (i % 2 == 0)
{ p = 1; q = 0; }
else
{ p = 0; q = 1; }
for (int j = 1; j <= i; j++)
if (j % 2 == 0)
System.out.print(p);
else
System.out.print(q);
System.out.println();
}
}
}
output
run:
1
01
101
0101
10101
=======================================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
/**
*
* @author rajesh kumar shukla
*/
public class pattern22 {
public static void main(String[] args) {
int n = 5;
for (int i = n; i >= 0; i--) {
for (int j = 1; j <= i; j++)
System.out.print(j);
System.out.println();
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++)
System.out.print(j);
System.out.println();
}
System.out.println();
}
}
out put
run:
12345
1234
123
12
1
1
12
123
1234
12345
========================================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
/**
*
* @author rajesh kumar shukla
*/
public class pattern23 {
public static void main(String[] args) {
int n = 5;
for (int i = 1; i < n; i++) {
for (int j = 1; j <= i; j++)
System.out.print(j);
System.out.println();
}
for (int i = n; i >= 0; i--) {
for (int j = 1; j <= i; j++)
System.out.print(j);
System.out.println();
}
System.out.println();
}
}
out put
run:
1
12
123
1234
12345
1234
123
12
1
========================================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
/**
*
* @author rajesh kumar shukla
*/
public class pattern24 {
public static void main(String[] args) {
int count = 5;
for (int i = 1; i <= count; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(i);
}
System.out.println();
}
}
}
out put
run:
1
22
333
4444
55555
========================================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
import java.util.Scanner;
/**
*
* @author rajesh kumar shukla
*/
public class pattern25 {
public static void main(String[] args) {
int num, space;
System.out.print("Enter a number between 1 to 9 : ");
Scanner reader = new Scanner(System.in);
try {
num = reader.nextInt();
space = num - 1;
for (int i = 1; i <= num; i++) {
for (space = 1; space <= (num - i); space++) {
System.out.print(" ");
}
for (int j = 1; j <= i; j++) {
System.out.print(j);
}
for (int k = (i - 1); k >= 1; k--) {
System.out.print(k);
}
System.out.println();
}
} finally {
reader.close();
}
}
}
out put
run:
Enter a number between 1 to 9 : 4
1
121
12321
1234321
====================================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
import java.util.Scanner;
/**
*
* @author rajesh kumar shukla
*/
public class pattern26 {
public static void main(String[] args) {
char[] letter = { '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 letter_number = 0;
// array of strings
String[] diamond = new String[26];
// get the letter
System.out.print("Enter a Char between A to Z : ");
Scanner reader = new Scanner(System.in);
try {
char user_letter = reader.next("[A-Z]").charAt(0);
// search for letter number in the array letter
for (int i = 0; i < letter.length; i++) {
if (letter[i] == user_letter) {
letter_number = i;
break;
}
}
// construct diamond
for (int i = 0; i <= letter_number; i++) {
diamond[i] = "";
// add initial spaces
for (int j = 0; j < letter_number - i; j++) {
diamond[i] += " ";
}
// add letter (first time)
diamond[i] += letter[i];
// add space between letters
if (letter[i] != 'A') {
for (int j = 0; j < 2 * i - 1; j++) {
diamond[i] += " ";
}
// add letter (second time)
diamond[i] += letter[i];
}
// Draw the first part of the diamond as it's composing.
System.out.println(diamond[i]);
}
for (int i = letter_number - 1; i >= 0; i--) {
// Draw the second part of the diamond
// Writing the diamondArray in reverse order.
System.out.println(diamond[i]);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
reader.close();
}
}
}
out put
run:
Enter a Char between A to Z : H
A
B B
C C
D D
E E
F F
G G
H H
G G
F F
E E
D D
C C
B B
A
=====================================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
/**
*
* @author rajesh kumar shukla
*/
public class pattern28 {
public static void main(String[] args) {
for (int i = 1; i <= 4; i++)
{
int n = 4;
for (int 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();
}
for (int i = 3; i >= 1; i--)
{
int n = 3;
for (int j = 0; 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();
}
}
}
out put
run:
1
212
32123
4321234
32123
212
1
========================================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
/**
*
* @author rajesh kumar shukla
*/
public class pattern29 {
public static void main(String[] args) {
int number, i, k, count = 1;
number = 5;
count = number - 1;
for (k = 1; k <= number; 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 <= number - 1; k++)
{
for (i = 1; i <= count; i++)
System.out.print(" ");
count++;
for (i = 1; i <= 2 * (number - k) - 1; i++)
System.out.print("*");
System.out.println();
}
}
}
out put
run:
*
***
*****
*******
*********
*******
*****
***
*
BUILD SUCCESSFUL (total time: 0 seconds)
========================================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
/**
*
* @author rajesh kumar shukla
*/
public class pattern30 {
public static void main(String[] args) {
int n = 5;
for (int i = 0; i < n; i++) {
int number = 1;
System.out.printf("%" + (n - i) * 2 + "s", "");
for (int j = 0; j <= i; j++) {
System.out.printf("%4d", number);
number = number * (i - j) / (j + 1);
}
System.out.println();
}
}
}
out put
run:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
BUILD SUCCESSFUL (total time: 0 seconds)
========================================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
/**
*
* @author rajesh kumar shukla
*/
public class pattern31 {
public static void main(String[] args) {
int i, j, k = 1;
for (i = 1; i <= 5; i++) {
for (j = 1; j < i + 1; j++) {
System.out.print(k++ + " ");
}
System.out.println();
}
}
}
out put
run:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
BUILD SUCCESSFUL (total time: 0 seconds)
========================================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
import java.util.Scanner;
/**
*
* @author rajesh kumar shukla
*/
public class pattern32 {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
//Taking rows value from the user
System.out.println("How many rows you want in this pattern?");
int rows = sc.nextInt();
System.out.println("Here is your pattern....!!!");
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= i; j++)
{
System.out.print(i+" ");
}
System.out.println();
}
//Close the resources
sc.close();
}
}
out put
run:
How many rows you want in this pattern?
4
Here is your pattern....!!!
1
2 2
3 3 3
4 4 4 4
BUILD SUCCESSFUL (total time: 4 seconds)
======================================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
import java.util.Scanner;
/**
*
* @author rajesh kumar shukla
*/
public class pattern33 {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
//Taking rows value from the user
System.out.println("How many rows you want in this pattern?");
int rows = sc.nextInt();
System.out.println("Here is your pattern....!!!");
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= i; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
//Close the resources
sc.close();
}
}
out put
run:
How many rows you want in this pattern?
5
Here is your pattern....!!!
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
BUILD SUCCESSFUL (total time: 3 seconds)
======================================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
import java.util.Scanner;
/**
*
* @author rajesh kumar shukla
*/
public class pattern34 {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
//Taking rows value from the user
System.out.println("How many rows you want in this pattern?");
int rows = sc.nextInt();
System.out.println("Here is your pattern....!!!");
//Printing upper half of the pattern
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= i; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
//Printing lower half of the pattern
for (int i = rows-1; i >= 1; i--)
{
for (int j = 1; j <= i; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
//Closing the resources
sc.close();
}
}
out put
run:
How many rows you want in this pattern?
5
Here is your pattern....!!!
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
BUILD SUCCESSFUL (total time: 3 seconds)
======================================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
import java.util.Scanner;
/**
*
* @author rajesh kumar shukla
*/
public class pattern35 {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
//Taking rows value from the user
System.out.println("How many rows you want in this pattern?");
int rows = sc.nextInt();
System.out.println("Here is your pattern....!!!");
for (int i = rows; i >= 1; i--)
{
for (int j = 1; j <= i; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
//Closing the resources
sc.close();
}
}
output
run:
How many rows you want in this pattern?
5
Here is your pattern....!!!
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
BUILD SUCCESSFUL (total time: 3 seconds)
=======================================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
import java.util.Scanner;
/**
*
* @author rajesh kumar shukla
*/
public class pattern36 {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
//Taking rows value from the user
System.out.println("How many rows you want in this pattern?");
int rows = sc.nextInt();
System.out.println("Here is your pattern....!!!");
for (int i = 1; i <= rows; i++)
{
for (int j = rows; j >= i; j--)
{
System.out.print(j+" ");
}
System.out.println();
}
//Closing the resources
sc.close();
}
}
out put
run:
How many rows you want in this pattern?
5
Here is your pattern....!!!
5 4 3 2 1
5 4 3 2
5 4 3
5 4
5
BUILD SUCCESSFUL (total time: 2 seconds)
=======================================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
import java.util.Scanner;
/**
*
* @author rajesh kumar shukla
*/
public class pattern37 {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
//Taking rows value from the user
System.out.println("How many rows you want in this pattern?");
int rows = sc.nextInt();
System.out.println("Here is your pattern....!!!");
for (int i = rows; i >= 1; i--)
{
for (int j = rows; j >= i; j--)
{
System.out.print(j+" ");
}
System.out.println();
}
//Closing the resources
sc.close();
}
}
out put
run:
How many rows you want in this pattern?
5
Here is your pattern....!!!
5
5 4
5 4 3
5 4 3 2
5 4 3 2 1
BUILD SUCCESSFUL (total time: 3 seconds)
========================================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
import java.util.Scanner;
/**
*
* @author rajesh kumar shukla
*/
public class pattern38 {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
//Taking rows value from the user
System.out.println("How many rows you want in this pattern?");
int rows = sc.nextInt();
System.out.println("Here is your pattern....!!!");
for (int i = rows; i >= 1; i--)
{
for (int j = i; j >= 1; j--)
{
System.out.print(j+" ");
}
System.out.println();
}
//Closing the resources
sc.close();
}
}
out put
run:
How many rows you want in this pattern?
5
Here is your pattern....!!!
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1
BUILD SUCCESSFUL (total time: 2 seconds)
==============================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
import java.util.Scanner;
/**
*
* @author rajesh kumar shukla
*/
public class pattern39 {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
//Taking rows value from the user
System.out.println("How many rows you want in this pattern?");
int rows = sc.nextInt();
System.out.println("Here is your pattern....!!!");
//Printing upper half of the pattern
for (int i = rows; i >= 1; i--)
{
for (int j = 1; j <= i; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
//Printing lower half of the pattern
for (int i = 2; i <= rows; i++)
{
for (int j = 1; j <= i; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
//Closing the resources
sc.close();
}
}
out put
run:
How many rows you want in this pattern?
5
Here is your pattern....!!!
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
BUILD SUCCESSFUL (total time: 2 seconds)
========================================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
import java.util.Scanner;
/**
*
* @author rajesh kumar shukla
*/
public class pattern40 {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
//Taking rows value from the user
System.out.println("How many rows you want in this pattern?");
int rows = sc.nextInt();
System.out.println("Here is your pattern....!!!");
for (int i = 1; i <= rows; i++)
{
//Printing first half of the row
for (int j = 1; j <= i; j++)
{
System.out.print(j+" ");
}
//Printing second half of the row
for (int j = i-1; j >= 1; j--)
{
System.out.print(j+" ");
}
System.out.println();
}
//Closing the resources
sc.close();
}
}
out put
run:
How many rows you want in this pattern?
5
Here is your pattern....!!!
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
BUILD SUCCESSFUL (total time: 2 seconds)
===================================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
import java.util.Scanner;
/**
*
* @author rajesh kumar shukla
*/
public class pattern41 {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
//Taking rows value from the user
System.out.println("How many rows you want in this pattern?");
int rows = sc.nextInt();
System.out.println("Here is your pattern....!!!");
for (int i = 1; i <= rows; i++)
{
for (int j = i; j >= 1; j--)
{
System.out.print(j+" ");
}
System.out.println();
}
//Close the resources
sc.close();
}
}
out put
run:
How many rows you want in this pattern?
5
Here is your pattern....!!!
1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
BUILD SUCCESSFUL (total time: 2 seconds)
==========================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
import java.util.Scanner;
/**
*
* @author rajesh kumar shukla
*/
public class pattern42 {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
//Taking rows value from the user
System.out.println("How many rows you want in this pattern?");
int rows = sc.nextInt();
System.out.println("Here is your pattern....!!!");
//Printing upper half of the pattern
for (int i = 1; i <= rows; i++)
{
//Printing i spaces at the beginning of each row
for (int j = 1; j < i; j++)
{
System.out.print(" ");
}
//Printing i to rows value at the end of each row
for (int j = i; j <= rows; j++)
{
System.out.print(j);
}
System.out.println();
}
//Printing lower half of the pattern
for (int i = rows-1; i >= 1; i--)
{
//Printing i spaces at the beginning of each row
for (int j = 1; j < i; j++)
{
System.out.print(" ");
}
//Printing i to rows value at the end of each row
for (int j = i; j <= rows; j++)
{
System.out.print(j);
}
System.out.println();
}
//Closing the resources
sc.close();
}
}
out put
run:
How many rows you want in this pattern?
5
Here is your pattern....!!!
12345
2345
345
45
5
45
345
2345
12345
BUILD SUCCESSFUL (total time: 2 seconds)
===================================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
import java.util.Scanner;
/**
*
* @author rajesh kumar shukla
*/
public class pattern43 {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
//Taking rows value from the user
System.out.println("How many rows you want in this pattern?");
int rows = sc.nextInt();
System.out.println("Here is your pattern....!!!");
//Printing upper half of the pattern
for (int i = 1; i <= rows; i++)
{
//Printing i spaces at the beginning of each row
for (int j = 1; j < i; j++)
{
System.out.print(" ");
}
//Printing i to rows value at the end of each row
for (int j = i; j <= rows; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
//Printing lower half of the pattern
for (int i = rows-1; i >= 1; i--)
{
//Printing i spaces at the beginning of each row
for (int j = 1; j < i; j++)
{
System.out.print(" ");
}
//Printing i to rows value at the end of each row
for (int j = i; j <= rows; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
//Closing the resources
sc.close();
}
}
out put
run:
How many rows you want in this pattern?
5
Here is your pattern....!!!
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
BUILD SUCCESSFUL (total time: 2 seconds)
========================================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
import java.util.Scanner;
/**
*
* @author rajesh kumar shukla
*/
public class pattern44 {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("How many rows you want in this pattern?");
int rows = sc.nextInt();
System.out.println("Here is your pattern....!!!");
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= i; j++)
{
if(j%2 == 0)
{
System.out.print(0);
}
else
{
System.out.print(1);
}
}
System.out.println();
}
sc.close();
}
}
out put
run:
How many rows you want in this pattern?
5
Here is your pattern....!!!
1
10
101
1010
10101
BUILD SUCCESSFUL (total time: 2 seconds)
========================================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
import java.util.Scanner;
/**
*
* @author rajesh kumar shukla
*/
public class pattern45 {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("How many rows you want in this pattern?");
int rows = sc.nextInt();
System.out.println("Here is your pattern....!!!");
for (int i = 1; i <= rows; i++)
{
int num;
if(i%2 == 0)
{
num = 0;
for (int j = 1; j <= rows; j++)
{
System.out.print(num);
num = (num == 0)? 1 : 0;
}
}
else
{
num = 1;
for (int j = 1; j <= rows; j++)
{
System.out.print(num);
num = (num == 0)? 1 : 0;
}
}
System.out.println();
}
sc.close();
}
}
out put
run:
How many rows you want in this pattern?
5
Here is your pattern....!!!
10101
01010
10101
01010
10101
BUILD SUCCESSFUL (total time: 2 seconds)
========================================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
import java.util.Scanner;
/**
*
* @author rajesh kumar shukla
*/
public class pattern46 {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("How many rows you want in this pattern?");
int rows = sc.nextInt();
System.out.println("Here is your pattern....!!!");
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= rows-i; j++)
{
System.out.print(1);
}
for (int j = 1; j <= i; j++)
{
System.out.print(i);
}
System.out.println();
}
sc.close();
}
}
out put
run:
How many rows you want in this pattern?
5
Here is your pattern....!!!
11111
11122
11333
14444
55555
BUILD SUCCESSFUL (total time: 2 seconds)
=====================================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
import java.util.Scanner;
/**
*
* @author rajesh kumar shukla
*/
public class pattern47 {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("How many rows you want in this pattern?");
int rows = sc.nextInt();
System.out.println("Here is your pattern....!!!");
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < rows; j++)
{
if(i == j)
{
System.out.print(i);
}
else
{
System.out.print(0);
}
}
System.out.println();
}
sc.close();
}
}
out put
run:
How many rows you want in this pattern?
5
Here is your pattern....!!!
00000
01000
00200
00030
00004
BUILD SUCCESSFUL (total time: 2 seconds)
=================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
import java.util.Scanner;
/**
*
* @author rajesh kumar shukla
*/
public class pattern48 {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("How many rows you want in this pattern?");
int rows = sc.nextInt();
System.out.println("Here is your pattern....!!!");
for (int i = 1; i <= rows; i++)
{
int num = i;
for (int j = 1; j <= i; j++)
{
System.out.print(num+" ");
num = num+rows-j;
}
System.out.println();
}
sc.close();
}
}
out put
run:
How many rows you want in this pattern?
5
Here is your pattern....!!!
1
2 6
3 7 10
4 8 11 13
5 9 12 14 15
BUILD SUCCESSFUL (total time: 2 seconds)
========================================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
import java.util.Scanner;
/**
*
* @author rajesh kumar shukla
*/
public class pattern49 {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
//Taking noOfRows value from the user
System.out.println("How Many Rows You Want In Your Pyramid?");
int noOfRows = sc.nextInt();
//Initializing rowCount with 1
int rowCount = 1;
System.out.println("Here Is Your Pyramid");
//Implementing the logic
for (int i = noOfRows; i > 0; i--)
{
//Printing i spaces at the beginning of each row
for (int j = 1; j <= i; j++)
{
System.out.print(" ");
}
//Printing 'rowCount' value 'rowCount' times at the end of each row
for (int j = 1; j <= rowCount; j++)
{
System.out.print(rowCount+" ");
}
System.out.println();
//Incrementing the rowCount
rowCount++;
}
}
}
out put
run:
How Many Rows You Want In Your Pyramid?
5
Here Is Your Pyramid
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
BUILD SUCCESSFUL (total time: 2 seconds)
=============================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
import java.util.Scanner;
/**
*
* @author rajesh kumar shukla
*/
public class pattern50 {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
//Taking noOfRows value from the user
System.out.println("How Many Rows You Want In Your Pyramid?");
int noOfRows = sc.nextInt();
//Initializing rowCount with 1
int rowCount = 1;
System.out.println("Here Is Your Pyramid");
//Implementing the logic
for (int i = noOfRows; i > 0; i--)
{
//Printing i spaces at the beginning of each row
for (int j = 1; j <= i; j++)
{
System.out.print(" ");
}
//Printing 'j' value at the end of each row
for (int j = 1; j <= rowCount; j++)
{
System.out.print(j+" ");
}
System.out.println();
//Incrementing the rowCount
rowCount++;
}
}
}
out put
run:
How Many Rows You Want In Your Pyramid?
5
Here Is Your Pyramid
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
BUILD SUCCESSFUL (total time: 2 seconds)
============================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package patterns;
import java.util.Scanner;
/**
*
* @author rajesh kumar shukla
*/
public class pattern51 {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
//Taking noOfRows value from the user
System.out.println("How Many Rows You Want In Your Pyramid?");
int noOfRows = sc.nextInt();
//Initializing rowCount with 1
int rowCount = 1;
System.out.println("Here Is Your Pyramid");
//Implementing the logic
for (int i = noOfRows; i > 0; i--)
{
//Printing i spaces at the beginning of each row
for (int j = 1; j <= i; j++)
{
System.out.print(" ");
}
//Printing * at the end of each row
for (int j = 1; j <= rowCount; j++)
{
System.out.print("* ");
}
System.out.println();
//Incrementing the rowCount
rowCount++;
}
}
}
out put
run:
How Many Rows You Want In Your Pyramid?
5
Here Is Your Pyramid
*
* *
* * *
* * * *
* * * * *
BUILD SUCCESSFUL (total time: 3 seconds)
0 comments:
Post a Comment