×
FREE ASSISTANCE FOR THE INQUISITIVE PEOPLE
Tutorial Topics
X
softetechnologies
Java Examples : Patterns Part 2 Numbers Program In Java
Java Examples : Patterns Part 3 - Java
5892    Arnab De    12/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

java pattern

import java.util.*;
public class Pat17
{
public static void main(String []args)
{
int n,c,r,s;
Scanner sc=new Scanner(System.in);
System.out.print("Enter Line no : ");

softetechnologies

n=sc.nextInt();
for(r=1;r<=n;r++)
{
for(s=1;s<=n-r;s++)
{
System.out.print(" ");
}
for(c=1;c<=2*r-1;c++)
{
System.out.print("*");
}
System.out.println("");
}
}
}

java pattern

import java.util.*;
public class Pat18
{
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=1;
for(s=1;s<=n-r;s++)
{

softetechnologies

System.out.print(" ");
}
for(c=1;c<=2*r-1;c++)
{
System.out.print("" + p);
if(c<r)
{
p++;
}
else
{
p--;
}
}
System.out.println("");
}
}
}

java pattern

import java.util.*;
public class Pat19
{
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=r;
for(s=1;s<=n-r;s++)
{
System.out.print(" ");
}
for(c=1;c<=2*r-1;c++)
{
System.out.print("" + p);
if(c<r)
{
p++;
}
else
{
p--;
}
}
System.out.println("");
}
}
}

java pattern

import java.util.*;
public class Pat20
{
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();

softetechnologies

for(r=1;r<=n;r++)
{
p=1;
for(s=1;s<=n-r;s++)
{
System.out.print(" ");
}
for(c=1;c<=2*r-1;c++)
{
System.out.print("" + p);
p=(p==0)?1:0;
}
System.out.println("");
}
}
}

java pattern

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

java pattern

import java.util.*;
public class Pat22
{
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-1;s++)
{
System.out.print(" ");
}

softetechnologies

for(c=1;c<=2*(n-r)+1;c++)
{
System.out.print("*");
}
System.out.println("");
}
}
}

java pattern

import java.util.*;
public class Pat23
{
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=1;
for(s=1;s<=r-1;s++)
{
System.out.print(" ");
}
for(c=1;c<=2*(n-r)+1;c++)
{
System.out.print(""+p);
if(c<n-r+1)
{
p++;
}
else
{
p--;
}
}
System.out.println("");
}
}
}

java pattern

import java.util.*;
public class Pat24
{
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-r+1;
for(s=1;s<=r-1;s++)
{
System.out.print(" ");
}
for(c=1;c<=2*(n-r)+1;c++)
{
System.out.print(""+p);
if(c<n-r+1)
{
p--;
}
else
{
p++;
}
}
System.out.println("");
}
}
}

java pattern

import java.util.*;
public class Pat25
{
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<=2*n-1;r++)
{
for(s=1;s<=Math.abs(n-r);s++)
{
System.out.print(" ");
}
p=n-Math.abs(n-r);
for(c=1;c<=2*p-1;c++)
{
System.out.print("*");
}
System.out.println("");
}
}
}

java pattern

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

java pattern

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

Java Examples : Patterns Part 2 Numbers Program In Java
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
Education is the manifestationof the perfection already in man.
Swami Vivekananda
2326
74.33
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     52155
25/06/2018     43929
01/01/2018     42926
28/06/2017     40679
02/08/2017     39504
01/08/2017     33691
06/07/2017     33510
15/05/2017     32786
14/07/2017     29058
11/09/2018     29013
softetechnologies