Java program to generate a invert Triangle 4444 333 22 1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/* Write a program to Display Invert Triangle.
   Example:
   Input - 5
   Output :
   5 5 5 5 5
   4 4 4 4
   3 3 3
   2 2
   1
 */
class InvertTriangle{
	public static void main(String args[]){
		int num = Integer.parseInt(args[0]);
		while(num > 0){
			for(int j=1;j<=num;j++){
				System.out.print(" "+num+" ");
			}
			System.out.print("\n");
			num--;
		}
	}
}

10 Responses to “Java program to generate a invert Triangle 4444 333 22 1”

    • public static void main(String args[]){
      int num = 10; //taking no. as command line
      String alphabates=”ABCDEFGHIJKLMNOPQRSTUVWXYZ”;

      while(num > 0 && num<27){
      for(int j=0;j<num;j++){
      System.out.print(alphabates.charAt(j)+" ");
      }
      System.out.print("\n");
      num–;
      }
      }

      Reply
    • public static void main(String args[]){
      int num = 4;
      String alphabates=”ABCDEFGHIJKLMNOPQRSTUVWXYZ”;

      if(num>0 && num<27){
      for(int a=0;a<num;a++){
      for(int b=0;b 0 && num<27){
      for(int j=0;j<num;j++){
      System.out.print(alphabates.charAt(j)+" ");
      }
      System.out.print("\n");
      num–;
      }
      }

      /* OUTPUT :
      A
      A B
      A B C
      A B C D
      A B C
      A B
      A
      */

      Reply
  1. Shekar

    1 2 17 18
    3 4 5 14 15 16
    6 7 8 12 13
    9 10 11 .how slove this pattern in Java .

    Reply

Leave a Reply