ICSE Class 9 Computer Applications
Question 9 of 17
Conditional Constructs in Java — Question 9
Back to all questions 9
Question Question 9
Write a program in Java to compute the perimeter and area of a triangle, with its three sides given as a, b, and c using the following formulas:
import java.util.Scanner;
public class KboatTriangle
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter first side: ");
double a = in.nextDouble();
System.out.print("Enter second side: ");
double b = in.nextDouble();
System.out.print("Enter third side: ");
double c = in.nextDouble();
double perimeter = a + b + c;
double s = perimeter / 2;
double area = Math.sqrt(s * (s - a) * (s - b) * (s - c));
System.out.println("Perimeter = " + perimeter);
System.out.println("Area = " + area);
}
}Output
