Java
import java.util.Scanner;
Try it Yourself ➠
Calculate area of a Triangle in JAVA
13 May
1
Write a program (WAP) in JAVA to read two numbers from keyboard(User Input) and calculate the area of a Triangle.
import java.util.Scanner;
class AreaOfTriangle
{
public static void main(String[] args)
{
Scanner s= new Scanner(System.in);
System.out.println("Enter Base of the triangle (b):");
double b= s.nextDouble();
System.out.println("Enter Height of the triangle (b):");
double h= s.nextDouble();
double area=(b*h)/2;
System.out.println("Area of Triangle is: " + area);
}
}
Try it Yourself ➠
Note :-
1. You can also write "double area=.5*b*h"
Must Read :-
Previous article
Next article
Nice code
ReplyDelete