×
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
4865    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.
Albert Einstein
Imagination is everything. It is the preview of life's coming attractions.
Albert Einstein
1649
50.01
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     41025
01/01/2018     35645
28/06/2017     33630
25/06/2018     32629
02/08/2017     31891
06/07/2017     26494
01/08/2017     26419
15/05/2017     26081
14/07/2017     21392
21/04/2018     20403
softetechnologies