Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- boolean iscorrect = true;
- int n = 0;
- System.out.println("This program finds the triangle with the largest radius of the circumscribed circle");
- do {
- System.out.println("Enter the number of triangles n(n > 2 and n < 10)");
- try {
- n = scanner.nextInt();
- if ((n > 1) && (n < 10)) {
- iscorrect = false;
- }
- }catch (Exception e) {
- scanner.nextLine();
- System.out.println("This is a mistake. Please enter again!");
- iscorrect = true;
- }
- }
- while (iscorrect);
- double a = 0;
- double b = 0;
- double c = 0;
- double p;
- int nomb = 0;
- double max = 0;
- double[] radius;
- radius = new double[n];
- for(int i = 0; i < n; i++ ) {
- System.out.print("Enter the sides of triangle № ");
- System.out.print(i + 1);
- do {
- try {
- do {
- try {
- System.out.println(" First side = ");
- a = scanner.nextInt();
- if (a > 0) {
- iscorrect = false;
- } else {
- System.out.println("This is a mistake. Please enter again!");
- iscorrect = true;
- }
- } catch (Exception e) {
- scanner.nextLine();
- System.out.println("This is a mistake. Please enter again!");
- iscorrect = true;
- }
- }
- while (iscorrect);
- do {
- try {
- System.out.println(" Second side = ");
- b = scanner.nextInt();
- if (b > 0) {
- iscorrect = false;
- } else {
- System.out.println("This is a mistake. Please enter again!");
- iscorrect = true;
- }
- } catch (Exception e) {
- scanner.nextLine();
- System.out.println("This is a mistake. Please enter again!");
- iscorrect = true;
- }
- }
- while (iscorrect);
- do {
- try {
- System.out.println(" Third side = ");
- c = scanner.nextInt();
- if (c > 0) {
- iscorrect = false;
- } else {
- System.out.println("This is a mistake. Please enter again!");
- iscorrect = true;
- }
- } catch (Exception e) {
- scanner.nextLine();
- System.out.println("This is a mistake. Please enter again!");
- iscorrect = true;
- }
- }
- while (iscorrect);
- if ((a + b > c) && (a + c > b) && (b + c > a)) {
- iscorrect = false;
- } else {
- iscorrect = true;
- 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!");
- }
- } catch (Exception e) {
- scanner.nextLine();
- System.out.println("This is a mistake. Please enter again!");
- iscorrect = true;
- }
- }
- while (iscorrect);
- p = (a + b + c) / 2;
- radius[i] = (a * b * c) / (4 * Math.sqrt(p * (p - a) * (p - b) * (p - c)));
- if (max < radius[i]) {
- max = radius[i];
- nomb = i;
- }
- }
- System.out.print("Triangle № " + (nomb + 1) + " has the largest radius of the circumscribed circle = " + max);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement