Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Questions;
- import java.util.Scanner;
- public class Q2 {
- //Return true if the sum of any two sides is greater than the third side.
- public static boolean isValid(double side1, double side2, double side3){
- if(side1+side2>side3) return true;
- if(side1+side3>side2) return true;
- if(side2+side3>side1) return true;
- return false;
- }
- //Return the area of the triangle.
- public static double area(double side1, double side2, double side3){
- double s = side1+side2+side3;
- s/=2.0;
- return Math.sqrt(s*(side1)*(s-side2)*(s-side3));
- }
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- System.out.println("Enter three sides in double: ");
- boolean valid = false;
- double s1,s2,s3;
- do{
- s1 = input.nextDouble();
- s2 = input.nextDouble();
- s3 = input.nextDouble();
- valid = isValid(s1,s2,s3);
- }while (!valid);
- System.out.println("Area: "+s1+s2+s3);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement