Tuesday, 20 January 2015

Java Program to print a Right Angled Triangle.


This is a Java Program which prints out a Right Angled triangle.

Java Program to print a Right angled triangle

PROGRAM : 
package codingcorner.in;

import java.util.Scanner;

public class RightAngledTriangle {
public static void main(String[] args) {
int i, j, n, k;
Scanner scan = new Scanner(System.in);
System.out.print("Enter number of lines[height of triangle] : \t");
n = scan.nextInt();
scan.close();
for (i = 1; i <= n; i++) {
for (j = i; j < n; j++) {
System.out.print(" ");
}
for (k = 1; k < (i * 2); k++) {

System.out.print(k++);
}
System.out.print("\n");
}
}
}

OUTPUT : 
Java Program to print a Right angled triangle

No comments:

Post a Comment