Pattern programs in Java

Today, we are going to do some pattern programs.

public static void main(String[] args) {
for(int no=1;no<=3;no++) {
for(int col=1;col<=3;col++) {

            System.out.print(no);
        }

        System.out.println();
    }
    // TODO Auto-generated method stub

}}

Output:

111
222
333

public static void main(String[] args) {
for(int no=1;no<=3;no++) {
for(int col=1;col<=no;col++) {

            System.out.print(no);
        }

        System.out.println();
    }
    // TODO Auto-generated method stub

}}

output:

1
22
333

public static void main(String[] args) {
for(int no=3;no>=1;no–) {
for(int col=1;col<=no;col++) {

            System.out.print(no);
        }

        System.out.println();
    }
    // TODO Auto-generated method stub

}}

Output:

333
22
1

From the above Programs we can see that when we change the values differently we’ll get the output in different ways.

Leave a comment

Design a site like this with WordPress.com
Get started