daily pastebin goal
69%
SHARE
TWEET

Area of Triangle V2 With If statements

a guest Sep 26th, 2016 72 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 AreaOfTriangleWithJustSides2 {
  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.         double s = (s1 + s2 + s3) / 2.0;
  23.         double temp = s * (s - s1) * (s - s2) * (s - s3);
  24.         if (temp < 0) {
  25.             System.out.println("Bad Sides!");
  26.         }
  27.         else {
  28.             double area = Math.sqrt(temp);
  29.             double areaDisp = (int) (area * 10.0) / 10.0;
  30.             System.out.println("Area = " + area);
  31.         }
  32.  
  33.         // Display results
  34.         // boolean valid = (edge1 + edge2 > edge3) && (edge1 + edge3 > edge2)
  35.         // && (edge2 + edge3 > edge1);
  36.  
  37.         // boolean valid;
  38.         // if (edge3 >= edge1 + edge2)
  39.         // valid = false;
  40.         // else if (edge2 >= edge1 + edge3)
  41.         // valid = false;
  42.         // else if (edge1 >= edge2 + edge3)
  43.         // valid = false;
  44.         // else
  45.         // valid = true;
  46.         //
  47.         // if (valid) {
  48.         // System.out.println("The perimeter of the triangle is "
  49.         // + (edge1 + edge2 + edge3));
  50.         // } else
  51.         // System.out.println("Input is invalid");
  52.         input.close();
  53.     }
  54.  
  55. }
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