×
FREE ASSISTANCE FOR THE INQUISITIVE PEOPLE
Tutorial Topics
X
softetechnologies
Java Examples : Patterns Part 1 Java Examples : Patterns Part 3
Java Examples : Patterns Part 2 - Java
3669    Arnab De    11/07/2017

Some another basic program which are print the different parttern. Here we use the "for loop" for the same. Students are request to understand how the minimum change of a program can convert into another pattern. At first assume a matrix box and put the items on it. For more pattern see the following page

softetechnologies

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


import java.util.*;
public class Pat9
{
public static void main(String []args)
{
int n,c,r;
Scanner sc=new Scanner(System.in);
System.out.print("Enter Line no : ");
n=sc.nextInt();
for(r=1;r<=n;r++)
{
for(c=1;c<=n-r+1;c++)
{
System.out.print("*");
}
System.out.println("");
}
}
}

123456
12345
1234
123
12
1

softetechnologies

import java.util.*;
public class Pat10
{
public static void main(String []args)
{
int n,c,r;
Scanner sc=new Scanner(System.in);
System.out.print("Enter Line no : ");
n=sc.nextInt();
for(r=1;r<=n;r++)
{
for(c=1;c<=n-r+1;c++)
{
System.out.print("" + c);
}
System.out.println("");
}
}
}

111111
22222
3333
444
55
6

import java.util.*;
public class Pat11
{
public static void main(String []args)
{
int n,c,r;
Scanner sc=new Scanner(System.in);
System.out.print("Enter Line no : ");
n=sc.nextInt();
for(r=1;r<=n;r++)
{
for(c=1;c<=n-r+1;c++)
{
System.out.print("" + r);
}
System.out.println("");
}
}
}

654321
65432
6543
654
65
6

import java.util.*;
public class Pat12
{
public static void main(String []args)
{
int n,c,r,p;
Scanner sc=new Scanner(System.in);
System.out.print("Enter Line no : ");
n=sc.nextInt();
for(r=1;r<=n;r++)
{
p=n;
for(c=1;c<=n-r+1;c++)
{
System.out.print("" + p);
p--;
}
System.out.println("");
}
}
}

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

import java.util.*;
public class Pat13
{
public static void main(String []args)
{
int n,c,r,s;
Scanner sc=new Scanner(System.in);
System.out.print("Enter Line no : ");
n=sc.nextInt();
for(r=1;r<=n;r++)
{
for(s=1;s<r;s++)
{
System.out.print(" ");
}
for(c=1;c<=n-r+1;c++)
{
System.out.print("*");
}
System.out.println("");
}
}
}

softetechnologies

123456
12345
1234
123
12
1

import java.util.*;
public class Pat14
{
public static void main(String []args)
{
int n,c,r,s;
Scanner sc=new Scanner(System.in);
System.out.print("Enter Line no : ");
n=sc.nextInt();
for(r=1;r<=n;r++)
{
for(s=1;s<r;s++)
{
System.out.print(" ");
}
for(c=1;c<=n-r+1;c++)
{
System.out.print("" + c);
}
System.out.println("");
}
}
}

111111
22222
3333
444
55
6

import java.util.*;
public class Pat15
{
public static void main(String []args)
{
int n,c,r,s;
Scanner sc=new Scanner(System.in);
System.out.print("Enter Line no : ");
n=sc.nextInt();
for(r=1;r<=n;r++)
{
for(s=1;s<r;s++)
{
System.out.print(" ");
}
for(c=1;c<=n-r+1;c++)
{
System.out.print("" + r);
}
System.out.println("");
}
}
}

softetechnologies

654321
65432
6543
654
65
6

import java.util.*;
public class Pat16
{
public static void main(String []args)
{
int n,c,r,s,p;
Scanner sc=new Scanner(System.in);
System.out.print("Enter Line no : ");
n=sc.nextInt();
for(r=1;r<=n;r++)
{
p=n;
for(s=1;s<r;s++)
{
System.out.print(" ");
}
for(c=1;c<=n-r+1;c++)
{
System.out.print("" + p);
p--;
}
System.out.println("");
}
}

Java Examples : Patterns Part 1 Java Examples : Patterns Part 3
softetechnologies
Author Details
Arnab De
I have over 16 years of experience working as an IT professional, ranging from teaching at my own institute to being a computer faculty at different leading institute across Kolkata. I also work as a web developer and designer, having worked for renowned companies and brand. Through tutorialathome, I wish to share my years of knowledge with the readers.
Enter New Comment
Comment History
No Comment Found Yet.
Sri Sri Ramakrishna Paramahamsa
God is in all men, but all men are not in God; that is why we suffer.
Sri Sri Ramakrishna Paramahamsa
1656
35.58
Today So Far
Total View (Lakh)
softetechnologies
01/01/2018     33880
28/06/2017     30126
26/05/2018     28037
02/08/2017     27820
15/05/2017     23768
25/06/2018     22412
06/07/2017     22314
01/08/2017     22297
21/04/2018     18818
14/07/2017     17257
softetechnologies