Advertisement
nikitaxe132

Untitled

Oct 10th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.59 KB | None | 0 0
  1. package com.company;
  2. import java.util.Scanner;
  3. public class Main {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.         boolean iscorrect = true;
  8.         int n = 0;
  9.         System.out.println("This program finds the triangle with the largest radius of the circumscribed circle");
  10.         do {
  11.             System.out.println("Enter the number of triangles n(n > 2 and n < 10)");
  12.             try {
  13.                 n = scanner.nextInt();
  14.                 if ((n > 1) && (n < 10)) {
  15.                     iscorrect = false;
  16.                 }
  17.             }catch (Exception e) {
  18.                 scanner.nextLine();
  19.                 System.out.println("This is a mistake. Please enter again!");
  20.                 iscorrect = true;
  21.             }
  22.         }
  23.         while (iscorrect);
  24.         double a = 0;
  25.         double b = 0;
  26.         double c = 0;
  27.         double p;
  28.         int nomb = 0;
  29.         double max = 0;
  30.         double[] radius;
  31.         radius = new double[n];
  32.         for(int i = 0; i < n; i++ ) {
  33.             System.out.print("Enter the sides of triangle № ");
  34.             System.out.print(i + 1);
  35.             do {
  36.                 try {
  37.                     do {
  38.                         try {
  39.                             System.out.println(" First side = ");
  40.                             a = scanner.nextInt();
  41.                             if (a > 0) {
  42.                                 iscorrect = false;
  43.                             } else {
  44.                                 System.out.println("This is a mistake. Please enter again!");
  45.                                 iscorrect = true;
  46.                             }
  47.                         } catch (Exception e) {
  48.                             scanner.nextLine();
  49.                             System.out.println("This is a mistake. Please enter again!");
  50.                             iscorrect = true;
  51.                         }
  52.                     }
  53.                     while (iscorrect);
  54.                     do {
  55.                         try {
  56.                             System.out.println(" Second side = ");
  57.                             b = scanner.nextInt();
  58.                             if (b > 0) {
  59.                                 iscorrect = false;
  60.                             } else {
  61.                                 System.out.println("This is a mistake. Please enter again!");
  62.                                 iscorrect = true;
  63.                             }
  64.                         } catch (Exception e) {
  65.                             scanner.nextLine();
  66.                             System.out.println("This is a mistake. Please enter again!");
  67.                             iscorrect = true;
  68.                         }
  69.                     }
  70.                     while (iscorrect);
  71.                     do {
  72.                         try {
  73.                             System.out.println(" Third side = ");
  74.                             c = scanner.nextInt();
  75.                             if (c > 0) {
  76.                                 iscorrect = false;
  77.                             } else {
  78.                                 System.out.println("This is a mistake. Please enter again!");
  79.                                 iscorrect = true;
  80.                             }
  81.                         } catch (Exception e) {
  82.                             scanner.nextLine();
  83.                             System.out.println("This is a mistake. Please enter again!");
  84.                             iscorrect = true;
  85.                         }
  86.                     }
  87.                     while (iscorrect);
  88.                     if ((a + b > c) && (a + c > b) && (b + c > a)) {
  89.                         iscorrect = false;
  90.                     } else {
  91.                         iscorrect = true;
  92.                         System.out.println("This is a mistake. The sides of the triangle must satisfy the condition (a + b > c and a + c > b and b + c > a).Please enter sides again!");
  93.                     }
  94.                 } catch (Exception e) {
  95.                     scanner.nextLine();
  96.                     System.out.println("This is a mistake. Please enter again!");
  97.                     iscorrect = true;
  98.                 }
  99.             }
  100.             while (iscorrect);
  101.             p = (a + b + c) / 2;
  102.             radius[i] = (a * b * c) / (4 * Math.sqrt(p * (p - a) * (p - b) * (p - c)));
  103.             if (max < radius[i]) {
  104.                 max = radius[i];
  105.                 nomb = i;
  106.             }
  107.         }
  108.         System.out.print("Triangle № " + (nomb + 1) + " has the largest radius of the circumscribed circle = " + max);
  109.     }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement