×
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
3998    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.
Swami Vivekananda
What makes one man great and another weak and low is shraddha (concentration).
Swami Vivekananda
2055
38.76
Today So Far
Total View (Lakh)
softetechnologies
01/01/2018     34311
28/06/2017     30951
26/05/2018     30901
02/08/2017     28863
25/06/2018     26242
15/05/2017     24616
01/08/2017     23466
06/07/2017     23189
21/04/2018     19221
14/07/2017     18487
softetechnologies