×
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
4903    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.
Rabindranath Tagore
A lamp can only light another lamp when it continues to burn in its own flame.
Rabindranath Tagore
16028
52.47
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     41979
01/01/2018     35991
28/06/2017     34082
25/06/2018     33432
02/08/2017     32394
01/08/2017     26806
06/07/2017     26783
15/05/2017     26415
14/07/2017     21851
21/04/2018     20711
softetechnologies