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--;
		}
	}
}
surajk

7 thoughts on “Java program to generate a invert Triangle 4444 333 22 1

  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–;
    }
    }

  2. 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
    */

Leave a Reply

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

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.

    StudentProjects.in