Java program to create a Triangle.
Input:
3
Output:
***
**
*
import java.io.*; import java.util.*; public class temp{ public static void main(String[] args) { int n; Scanner scan = new Scanner(System.in); System.out.print("Enter any number: "); n = scan.nextInt(); for(int i=0;i<n;i++){ for(int j=i;j<n;j++){ System.out.print("*"); } System.out.println(); } } }
INPUT_1:
Enter any number: 5
OUTPUT:
*****
****
***
**
*
INPUT_2:
Enter any number: 4
OUTPUT:
****
***
**
*
INPUT_3:
Enter any number: 2
OUTPUT:
**
*
INPUT_4:
Enter any number: 10
OUTPUT:
**********
*********
********
*******
******
*****
****
***
**
*
INPUT_5:
Enter any number: 6
OUTPUT:
******
*****
****
***
**
*
INPUT_6:
Enter any number: 8
OUTPUT:
********
*******
******
*****
****
***
**
*
ILLUSTRATION
