Tuesday, 20 January 2015

Java Program to print Palindrome triangle

This is a simple Java Program which prints out a Palindrome triangle with respect to the given input.

Java Program to print Palindrome triangle

PROGRAM :
package codingcorner.in;

import java.util.Scanner;

public class PalindromeTriangle {
 public static void main(String[] args) {
  int i, j, n;
  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 (j = 1; j <= i; j++)
    System.out.print(j);
   for (j = i - 1; j >= 1; j--)
    System.out.print(j);
   System.out.print("\n");
  }

 }
}


OUTPUT : 
Java Program to print Palindrome triangle