Thursday, July 9, 2015

Area of a Triangle in Java

In this article I would like to share with you a sample program that I wrote in Java programming language I called this program Area of a Triangle in Java that will compute the are of the triangle based on the based and height of the triangle given by the user.

Feel free to use my code in your programming projects at school or work.  If you have some questions please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

People here in the Philippines can reach me at my mobile number 09173084360.

Thank you very much and Happy Programming.



Sample Program Output

Program Listing

// area_of_the_triangle.java
// Written By: Mr. Jake R. Pomperada, BSCS, MAED-IT
// July 9, 2015   Thursday
// Email Address:  jakerpomperada@gmail.com 
//                 jakerpomperada@yahoo.com

import java.util.Scanner;
 
public class area_of_the_triangle {
 
   public static void main(String[] args) {
      Scanner input = new Scanner(System.in);
        
      char ch;
      double base_triangle = 0;
      double height_triangle = 0;
      double solve_area = 0;
 do {
      System.out.println();
      System.out.print("\tAREA OF THE TRIANGLE SOLVER ");
      System.out.println("\n\n");
      System.out.print("What is the length of base of the triangle : "); 
      base_triangle = input.nextDouble();
 
      System.out.print("What is the length of height of triangle : "); 
      height_triangle = input.nextDouble();
 
      solve_area = (base_triangle * height_triangle) / 2;
      
      System.out.println();
      System.out.println("The Area of Triangle is : " + solve_area + ".");
      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");
   }
 
}

No comments:

Post a Comment