×
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
4525    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
The world is needed a mixture of truth and make-believe. Discard the make-believe and take the truth.
Sri Sri Ramakrishna Paramahamsa
2065
44.94
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     36731
01/01/2018     34923
28/06/2017     32403
02/08/2017     30468
25/06/2018     30212
15/05/2017     25401
01/08/2017     24701
06/07/2017     24612
14/07/2017     20225
21/04/2018     19839
softetechnologies