×
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
6594    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.
Rabindranath Tagore
It is no easy task to lead men. But it is easy enough to drive them.
Rabindranath Tagore
2262
86.93
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     55055
25/06/2018     46195
01/01/2018     44263
28/06/2017     41878
02/08/2017     40960
01/08/2017     34957
06/07/2017     34702
15/05/2017     33887
11/09/2018     31711
14/07/2017     30852
softetechnologies