floyd triangle in java reverse code example

Example: Inverted floyd triangle in java

// Inverted floyd triangle in java
import java.util.Scanner;
public class InvertedFloydTriangleDemo
{
   public static void main(String[] args) 
   {
      Scanner sc = new Scanner(System.in);
      System.out.print("Please enter size limit: ");
      int num = sc.nextInt();
      int a, b, x = 0;
      System.out.println("Here's Inverted Floyd Triangle: ");
      for(a = 1; a <= num; a++)
      {
         for(b = 1; b <= a; b++)
            x++;
      }
      for(a = num; a >= 1; a--)
      {
         for(b = 1; b <= a; b++)
         {
            System.out.print(x + " ");
            x--;
         }
         System.out.println();
      }
      sc.close();
   }
}

Tags:

Java Example