+ Start a Discussion
yuvraj.chaudhari88@gmail.comyuvraj.chaudhari88@gmail.com 

write a code for printing the reverse triangle

PrasanntaPrasannta (Salesforce Developers) 
Please refer to below code to print triangle in java.
Try to execute it in eclipse(Force.com IDE)

import java.util.Scanner;
class RevTriangle{
  public static void main(String agrs[]){
    Scanner k = new Scanner (System.in);
    int line = k.nextInt();
    int x = (line * 2) - 1;
    int y = 1 ;

    for(int l = 0; l < line; l++){
     
      for(int s = y; s > 0; s--){
        System.out.print(" ");
      }
     
      for(int s = 0; s < x ; s++){
        System.out.print("*");
      }
     
      System.out.println();
      x-=2;
      y++;
    }
  }
}

Hope it helps.