daily pastebin goal
69%
SHARE
TWEET

Area of Triangle With If statements

a guest Sep 26th, 2016 124 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1.  
  2. /*
  3.  * Tony Silvestri
  4.  * 9/26/2016
  5.  * CSC-111 Intro to Java Programming
  6.  * Problem 2-19
  7.  * Area of Triangle Calculation Using Heron's Formula
  8.  */
  9.  
  10. import java.util.Scanner;
  11.  
  12. public class AreaOfTriangleWithJustSides {
  13.  
  14.     public static void main(String[] args) {
  15.         Scanner input = new Scanner(System.in);
  16.  
  17.         // Enter three edges
  18.         System.out.print("Enter three edges (length in double): ");
  19.         double s1 = input.nextDouble();
  20.         double s2 = input.nextDouble();
  21.         double s3 = input.nextDouble();
  22.  
  23.         if (s1 + s2 < s3) {
  24.             System.out.println("Bad Sides!");
  25.         }
  26.         else if (s1 + s3 < s2) {
  27.             System.out.println("Bad Sides!");
  28.         }
  29.         else if (s2 + s3 < s1) {
  30.             System.out.println("Bad Sides!");
  31.         }
  32.         else {
  33.             double s = (s1 + s2 + s3) / 2.0;
  34.             double area = Math.sqrt(s * (s - s1) * (s - s2) * (s - s3));
  35.             double areaDisp = (int) (area * 10.0) / 10.0;
  36.             System.out.println("Area = " + area);
  37.         }
  38.  
  39.         // Display results
  40.         // boolean valid = (edge1 + edge2 > edge3) && (edge1 + edge3 > edge2)
  41.         // && (edge2 + edge3 > edge1);
  42.  
  43.         // boolean valid;
  44.         // if (edge3 >= edge1 + edge2)
  45.         // valid = false;
  46.         // else if (edge2 >= edge1 + edge3)
  47.         // valid = false;
  48.         // else if (edge1 >= edge2 + edge3)
  49.         // valid = false;
  50.         // else
  51.         // valid = true;
  52.         //
  53.         // if (valid) {
  54.         // System.out.println("The perimeter of the triangle is "
  55.         // + (edge1 + edge2 + edge3));
  56.         // } else
  57.         // System.out.println("Input is invalid");
  58.         input.close();
  59.     }
  60.  
  61. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top