- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java program to find the area of a triangle
Area of a triangle is half the product of its base and height. Therefore, to calculate the area of a triangle.
- Get the height of the triangle form the user.
- Get the base of the triangle form the user.
- Calculate their product and divide the result with 2.
- Print the final result.
Example
import java.util.Scanner; public class AreaOfTriangle { public static void main(String args[]){ int height, base, area; Scanner sc = new Scanner(System.in); System.out.println("Enter the height of the triangle ::"); height = sc.nextInt(); System.out.println("Enter the base of the triangle ::"); base = sc.nextInt(); area = (height* base); System.out.println("Area of the triangle is ::"+area); } }
Output
Enter the height of the triangle :: 14 Enter the base of the triangle :: 5 Area of the triangle is ::70
Advertisements