Showing posts with label pascal triangle in java. Show all posts
Showing posts with label pascal triangle in java. Show all posts

Sunday, July 19, 2015

Pascal Triangle in Java

A simple program that I wrote using Java that will display Pascal Triangle using the value that is being given by the user.

I hope you will find my work useful and beneficial. If you have some questions about programming, about my work please send me an email at jakerpomperada@gmail.comand jakerpomperada@yahoo.com. People here in the Philippines can contact me at  my mobile number 09173084360.

Thank you very much and Happy Programming.


Sample Program Output

Program Listing

// pascal_triangle.java
// Programmer : Mr. Jake R. Pomperada, MAED-IT
// Date       : July 19, 2015
// Tools      : Netbeans 8.0.2
// Email      : jakerpomperada@yahoo.com and jakerpomperada@gmail.com

import java.util.Scanner;

public class pascal_triangle{

public static void main(String[] args) {
 Scanner input = new Scanner(System.in);
                char ch;
         do {   
      System.out.println();
               System.out.print("\t Pascal Triangle Generator ");
               System.out.println("\n");
      
               System.out.print("Enter a number please  : "); 
              int value = input.nextInt();
     System.out.println();
              for(int i =0;i<value;i++) {

              int number = 1;

              System.out.format("%"+(value-i)*2+"s","");

            for(int j=0;j<=i;j++) {
                 System.out.format("%4d",number);
                 number = number * (i - j) / (j + 1);
            }
           System.out.println();
        }
        System.out.print("\nDo you want to continue (Type y or n) : ");
       ch = input.next().charAt(0);                        
     } while (ch == 'Y'|| ch == 'y');  
      System.out.println();
      System.out.print("\t THANK YOU FOR USING THIS PROGRAM");
      System.out.println("\n\n");
}
}