Java program to print number pattern

      No Comments on Java program to print number pattern

Number pattern using Java:

OUTPUT:-

Number pattern

Number pattern using For Loop

import java.util.*;
class scan
{
public static void main(String arg[])
    {
		 
	 int i,j;
    for(i=5;i>=1;i--)
   {
    for(j=5;j>5-i;j--)
    {
   System.out.print(j+" ");
    }
   System.out.println();
    }
 }
}

Number pattern using for and while loop

import java.util.*;
class scan
{
public static void main(String arg[])
    {
		 
	 int i=5,j=5;
    while(i>=1)
   {
    for(j=5;j>5-i;j--)
    {
   System.out.print(j+" ");
    }
   System.out.println();
   
    i--;
    }
 }
}

Using While Loop

import java.util.*;
class scan
{
public static void main(String arg[])
    {
		 
	 int i=5,j;
    while(i>=1)
   {
		j=5;
    while(j>5-i)
    {
   System.out.print(j+" ");
       j--;
    }
	
   System.out.println();
    
    i--;
    }
 }
}

Leave a Reply

Your email address will not be published. Required fields are marked *