Cnvmendoza

Triangle Perimeter

May 7th, 2022 (edited)
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.58 KB | None | 0 0
  1. import java.io.*;
  2. /**
  3.  * Problem: The third side of the triangle is 8 less than twice the sum of
  4.  * the two other sides and the first side is 5 more than the thrice the
  5.  * second side. If the perimeter is given, how long are its sides?
  6.  * Input: float perimeter
  7.  * Output: float sides
  8.  * perimeter = 3 * second_side + 5 + second_side + 2 * (3 * second_side + 5) - 8
  9.  * perimeter = 10 * second_side + 7
  10.  * first_side = (3 * second_side) + 5
  11.  * second_side = (perimeter - 7) / 10
  12.  * third_side = 2 * (first_side + second_side) - 8
  13.  * third_side = 2 * (3 * second_side + 5 * second_side) - 8
  14.  *
  15.  * @author Carl Nicolas Mendoza, Kurt Charles Gonzaga
  16.  * @version 05/11/2022
  17.  */
  18. public class Assignment_1
  19. {
  20.     /**
  21.      * Main method of the application
  22.      *
  23.      * @param arg list of running arguments
  24.      * @return
  25.      */
  26.     public static void main( String[]args)
  27.     {
  28.         float perimeter = 0, first_side = 0, second_side = 0, third_side = 0;
  29.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  30.         try
  31.         {
  32.             System.out.print("What is the perimeter value: ");
  33.             perimeter = Float.parseFloat(br.readLine());
  34.             second_side = (perimeter - 7) / 12;
  35.             first_side = 3 * (second_side) + 5;
  36.             third_side = 2 * (3 * second_side + 5 + second_side) - 8;
  37.             System.out.println("First Side: " + first_side);
  38.             System.out.println("Second Side: " + second_side);
  39.             System.out.println("Third Side: " + third_side);
  40.         }
  41.         catch(IOException ex){}
  42.     }
  43. }
  44.  
Add Comment
Please, Sign In to add comment