Number Pattern Programs
Pattern 1:
Enter the number
5
11111
22222
33333
44444
55555
package patternprograms;
import java.util.Scanner;
public class Pattern1
{
public static void main(String args[])
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter the number");
int n=sc.nextInt();
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
System.out.print(i);
}
System.out.println(" ");
}
}
}
Pattern 2:
Enter the number
5
12345
12345
12345
12345
12345
package patternprograms;
import java.util.Scanner;
public class Pattern2
{
public static void main(String args[])
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter the number");
int n=sc.nextInt();
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
System.out.print(j);
}
System.out.println(" ");
}
}
}
Pattern 3:
Enter the number
5
1
22
333
4444
55555
package patternprograms;
import java.util.Scanner;
public class Pattern3
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number");
int n=sc.nextInt();
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print(i);
}
System.out.println(" ");
}
}
}
Pattern 4:
Enter the number
5
1
12
123
1234
12345
package patternprograms;
import java.util.Scanner;
public class Pattern4
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number");
int n=sc.nextInt();
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print(j);
}
System.out.println(" ");
}
}
}
Pattern 5:
package patternprograms;
import java.util.Scanner;
public class Pattern5
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number");
int n=sc.nextInt();
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n-i;j++)
{
System.out.print(" ");
}
for(int k=1;k<=i;k++)
{
System.out.print(i);
}
System.out.println(" ");
}
}
}
Pattern 6:
package patternprograms;
import java.util.Scanner;
public class Pattern6
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number");
int n=sc.nextInt();
for(int i=1;i<=n;i++)
{
for(int j=1;j<n-i+1;j++)
{
System.out.print(" ");
}
for(int k=1;k<=i;k++)
{
System.out.print(k);
}
System.out.println(" ");
}
}
}
Pattern 7:
package patternprograms;
import java.util.Scanner;
public class Pattern7
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number");
int n=sc.nextInt();
for(int i=n;i>=1;i--)
{
for(int k=1;k<=i;k++)
{
System.out.print(i);
}
System.out.println(" ");
}
}
}
Pattern 8:
package patternprograms;
import java.util.Scanner;
public class Pattern8
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number");
int n=sc.nextInt();
for(int i=n;i>=1;i--)
{
for(int j=1;j<=i;j++)
{
System.out.print(j);
}
System.out.println(" ");
}
}
}
Pattern 9:
package patternprograms;
import java.util.Scanner;
public class Pattern9
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number");
int n=sc.nextInt();
for(int i=1;i<=n;i++)
{
for(int j=n;j>=i;j--)
{
System.out.print(j);
}
System.out.println(" ");
}
}
}
Pattern 10:
package patternprograms;
import java.util.Scanner;
public class Pattern10
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number");
int n=sc.nextInt();
for(int i=1;i<=n;i++)
{
for(int j=n;j>=i;j--)
{
System.out.print(i);
}
System.out.println(" ");
}
}
}
Pattern 11:
package patternprograms;
import java.util.Scanner;
public class Pattern11
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number");
int n=sc.nextInt();
for(int i=1;i<=n;i++)
{
for(int j=n;j>=1;j--)
{
System.out.print(j);
}
System.out.println(" ");
}
}
}
Pattern 12:
package patternprograms;
import java.util.Scanner;
public class Pattern12
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number");
int n=sc.nextInt();
for(int i=n;i>=1;i--)
{
for(int j=1;j<=n;j++)
{
System.out.print(i);
}
System.out.println(" ");
}
}
}
Pattern 13:
package patternprograms;
import java.util.Scanner;
public class Pattern13
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number");
int n=sc.nextInt();
for(int i=1;i<=n;i++)
{
for(int j=i;j<=i+n;j++)
{
System.out.print(" "+j);
}
System.out.println("");
}
}
}
Pattern 14:
package patternprograms;
import java.util.Scanner;
public class Pattern14
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number");
int n=sc.nextInt();
for(int i=n;i>=1;i--)
{
for(int k=n;k>=i;k--)
{
System.out.print(i);
}
System.out.println(" ");
}
}
}
Pattern 15:
package patternprograms;
import java.util.Scanner;
public class Pattern15
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number");
int n=sc.nextInt();
for(int i=1;i<=n;i++)
{
for(int j=1;j<i;j++)
{
System.out.print(" ");
}
for(int k=i;k<=n;k++)
{
System.out.print(i);
}
System.out.println(" ");
}
}
}
Pattern 16:
package patternprograms;
import java.util.Scanner;
public class Pattern16
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number");
int n=sc.nextInt();
for(int i=1;i<=n;i++)
{
for(int j=1;j<i;j++)
{
System.out.print(" ");
}
for(int k=i;k<=n;k++)
{
System.out.print(k);
}
System.out.println(" ");
}
}
}
Pattern 17:
package patternprograms;
import java.util.Scanner;
public class Pattern17
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number");
int n=sc.nextInt();
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(i==j||i+j==n+1)
{
System.out.print(j);
}
else
System.out.print(" ");
}
System.out.println(" ");
}
}
}
Pattern 18:
package patternprograms;
import java.util.Scanner;
public class Pattern18
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number");
int n=sc.nextInt();
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(i==j||i+j==n+1)
{
System.out.print(i);
}
else
System.out.print(" ");
}
System.out.println(" ");
}
}
}
Pattern 19:
package patternprograms;
import java.util.Scanner;
public class Pattern19
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number");
int n=sc.nextInt();
for(int i=n;i>=1;i--)
{
for(int j=n;j>=1;j--)
{
if(i==j||i+j==n+1)
{
System.out.print(i);
}
else
System.out.print(" ");
}
System.out.println(" ");
}
}
}
Pattern 20:
package patternprograms;
import java.util.Scanner;
public class Pattern20
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number");
int n=sc.nextInt();
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print(j);
}
for(int k=i-1;k>=1;k--)
{
System.out.print(k);
}
System.out.println(" ");
}
}
}