0% found this document useful (0 votes)
1 views14 pages

Pattern Programs

The document provides a series of Java programs designed to display various patterns using loops. Each pattern is demonstrated with accompanying code snippets that illustrate how to generate the desired output. The patterns range from simple number sequences to more complex arrangements involving characters and symbols.

Uploaded by

afiyahasif2011
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views14 pages

Pattern Programs

The document provides a series of Java programs designed to display various patterns using loops. Each pattern is demonstrated with accompanying code snippets that illustrate how to generate the desired output. The patterns range from simple number sequences to more complex arrangements involving characters and symbols.

Uploaded by

afiyahasif2011
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

The J. B.

Vachha High School For Parsi Girls


CLASS - X
Computer Application

PATTERN PROGRAMS

Write the programs in Java to display the following patterns:

(a)

12345

12345

12345

12345

12345

public class Pattern


{
public static void main(String args[]) {
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= 5; j++) {
[Link](j + " ");
}
[Link]();
}
}

1
(b)

11111
22222
33333
44444
55555
public class Pattern
{
public static void main(String args[]) {
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= 5; j++) {
[Link](i + " ");
}
[Link]();
}
}
}

(c)
1
12
123

1234

12345

public class Pattern


{
public static void main(String args[]) {
for (int i = 1; i <= 5; i++) {
2
for (int j = 1; j <= i; j++) {
[Link](j + " ");
}
[Link]();
}
}
}

(d)

1
21
321
4321
54321

public class Pattern


{
public static void main(String args[]) {
for (int i = 1; i <= 5; i++) {
for (int j = i; j >= 1; j--) {
[Link](j + " ");
}
[Link]();
}
}
}

(e)

12345
1234
123
12
1
3
public class Pattern1
{
public static void main(String args[]) {
for (int i = 5; i >= 1; i--) {
for (int j = 1; j <= i; j++) {
[Link](j + " ");
}
[Link]();
}
}
}

(f)

11111
3333
555
77
9

public class Pattern


{
public static void main(String args[]) {
for (int i = 5, term = 1; i >= 0; i--, term += 2) {
for (int j = 1; j <= i; j++) {
[Link](term + " ");
}
[Link]();
}
}
}

4
(g)

54321
5432
543
54
5

public class Pattern


{
public static void main(String args[]) {
for (int i = 1; i <= 5; i++) {
for (int j = 5; j >= i; j--) {
[Link](j + " ");
}
[Link]();
}
}
}

(h)

13579
1357
135
13
1

public class Pattern


{
public static void main(String args[]) {
for (int i = 9; i >= 1; i -= 2) {
for (int j = 1; j <= i; j += 2) {
[Link](j + " ");
}
[Link]();
}
}
}

5
(i)

5
54
543
5432
54321

public class Pattern


{
public static void main(String args[]) {

for (int i = 5; i >= 1; i--) {


for (int j = 5; j >= i; j--) {
[Link](j + " ");
}
[Link]();
}
}
}

(j)

12345
2345
345
45
5

public class Pattern


{
public static void main(String args[]) {
for (int i = 1; i <= 5; i++) {
for (int j = i; j <= 5; j++) {
[Link](j + " ");
}
[Link]();
}

6
}
}

(k)

99999
77777
55555
33333
11111

public class Pattern


{
public static void main(String args[]) {
for (int i = 9; i >= 1; i -= 2) {
for (int j = 1; j <= 5; j++) {
[Link](i + " ");
}
[Link]();
}
}
}

(l)

9
79
579
3579
13579

public class Pattern


{
public static void main(String args[]) {

for (int i = 9; i >= 1; i -= 2) {


for (int j = i; j <= 9; j += 2) {

7
[Link](j + " ");
}
[Link]();
}
}
}

(m)

9
97
975
9753
97531

public class Pattern


{
public static void main(String args[]) {
for (int i = 9; i >= 1; i -= 2) {
for (int j = 9; j >= i; j -= 2) {
[Link](j + " ");
}
[Link]();
}
}
}

(n)

1
23
456
7 8 9 10
11 12 13 14 15

public class Pattern


{
8
public static void main(String args[]) {
int term = 1;
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
[Link](term++ + " ");
}
[Link]();
}
}
}

(o)

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

public class Pattern


{
public static void main(String args[]) {
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
[Link]("* ");
}
[Link]();
}}
}

(p)

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

9
public class Pattern
{
public static void main(String args[]) {
for (int i = 5; i >= 1; i--) {
for (int j = 1; j <= i; j++) {
[Link]("* ");
}
[Link]();
}
}

(q)

1
22
333
4444
55555

public class Pattern


{
public static void main(String args[]) {
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
[Link](i + " ");
}
[Link]();
}
}
}

(r)

55555
4444
333
22
1

10
public class Pattern
{
public static void main(String args[]) {
for (int i = 5; i > 0; i--) {
for (int j = 1; j <= i; j++) {
[Link](i + " ");
}
[Link]();
}
}}

(s)

3
56
8 9 10
12 13 14 15

public class Pattern


{
public static void main(String args[]) {
int t = 2;
for (int i = 1, j = 1; i <= 4; i++, j++) {
t += i;
for (int k = t, l = 1; l <= j; k++, l++)
[Link](k + " ");
[Link]();
}
}
}

(t)

*
* #
* # *
* # * #
* # * # *

11
public class Pattern
{
public static void main(String args[]) {
for (int i = 1; i <=5; i++) {
for (int j = 1; j <= i; j++) {
if (j % 2 == 0)
[Link]("# ");
else
[Link]("* ");
}
[Link]();
}
}
}

(u)

AB

ABC

ABCD

ABCDE

public class Pattern

public static void main(String args[]) {

char i,j;

for ( i = 'A'; i <= 'E'; i++) {

for ( j = 'A'; j <= i; j++) {

[Link](j + " ");

}
12
[Link]();

(v)

BB

CCC

DDDD

EEEEE

public class Pattern

public static void main(String args[]) {

char i,j;

for ( i = 'A'; i <= 'E'; i++) {

for ( j = 'A'; j <= i; j++) {

[Link](i + " ");

[Link]();

13
}
(w)

ABCDE

ABCD

ABC

AB

public class Pattern

public static void main(String args[]) {

char i,j;

for ( i = 'E'; i >= 'A'; i--) {

for ( j = 'A'; j <= i; j++) {

[Link](j + " ");

[Link]();

}
**************

14

You might also like