Q:

Java Program to generate a triangle

0

Program to generate a triangle by getting input from the user using for loops

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import java.util.Scanner;
public class demo1 {
   public static void main(String args[]) 
    {
        Scanner input = new Scanner(System.in);
        System.out.print("Input the number: ");
        int n = input.nextInt();
        for (int i = n; i > 0; i--) 
        {
            for (int a = n - i; a > 0; a--) 
            {
                System.out.print(" ");
            }
            for (int j = 0; j < i; j++) 
            {
                System.out.print("*");
            }
            System.out.println();
        }
    }

}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now