Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. package Questions;
  2. import java.util.Scanner;
  3. public class Q2 {
  4. //Return true if the sum of any two sides is greater than the third side.
  5. public static boolean isValid(double side1, double side2, double side3){
  6. if(side1+side2>side3) return true;
  7. if(side1+side3>side2) return true;
  8. if(side2+side3>side1) return true;
  9. return false;
  10. }
  11. //Return the area of the triangle.
  12. public static double area(double side1, double side2, double side3){
  13. double s = side1+side2+side3;
  14. s/=2.0;
  15. return Math.sqrt(s*(side1)*(s-side2)*(s-side3));
  16. }
  17. public static void main(String[] args) {
  18. Scanner input = new Scanner(System.in);
  19. System.out.println("Enter three sides in double: ");
  20. boolean valid = false;
  21. double s1,s2,s3;
  22. do{
  23. s1 = input.nextDouble();
  24. s2 = input.nextDouble();
  25. s3 = input.nextDouble();
  26. valid = isValid(s1,s2,s3);
  27. }while (!valid);
  28. System.out.println("Area: "+s1+s2+s3);
  29.  
  30.  
  31.  
  32. }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement