Java Online Compiler
Example: Java program to find the area of a triangle if base and height are given
C
C++
C#
Java
Python
PHP
Main.java
STDIN
Run
// Java program to find the area of a triangle if base and height are given import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Enter the base & height of the triangle::\n"); float b = in.nextFloat(); float h = in.nextFloat(); float a; // b = base // h = height // a = area // Calculate area of the triangle a = (float)((b * h) / 2); // Output System.out.println("\nArea of the triangle = " + a + " sq. units\n"); } }
5 7
Output
Clear
ADVERTISEMENTS