EX: Write a java program to find area of triangle. How to write a java program to find area of triangle. Java program to find area of triangle.
Program to find area of triangle:
import java.util.Scanner;
public class AreaofTriangle {
public static void main(String[] args) {
int b, h;
float area;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the base of triangle: ");
b = sc.nextInt();
System.out.println("Enter the height of triangle: ");
h = sc.nextInt();
area = (b*h)/2;
System.out.println("Area of triangle is: "+area);
}
}
Above java code shows the following output:Enter the base of triangle: 11
Enter the height of triangle: 22
Area of triangle is: 121.0
No comments:
Post a Comment
If you have any doubts, please discuss here...👇