Reverse Number triangle pyramid program in Java.





package demo;
import java.util.Scanner;
public class ReverseNumberTriangle
{
 public static void main(String[] args) 
 {
  int num;
  Scanner sc = new Scanner(System.in);
  System.out.print("Enter any number : ");
  num = sc.nextInt();
  for (int r = 1; r <= num; r++) 
  {
   for (int sp = 1; sp < r; sp++) 
   {
    System.out.print(" ");
   }
   for (int c = r; c <= num; c++) 
   {
    System.out.print(c + " ");
   }
   System.out.println();
  }
 }
}

Output:

Enter any number : 6

1 2 3 4 5 6 
 2 3 4 5 6 
  3 4 5 6 
   4 5 6 
    5 6 
     6 

BUILD SUCCESSFUL (total time: 4 seconds)


No comments:

Post a Comment