Advertisement
LisunovaMaryna

lab1.1 java

Sep 25th, 2023 (edited)
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.64 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Main
  3. {
  4.     public static void main(String[]args)
  5.     {
  6.         int radius = 0, side = 0;
  7.         Scanner in = new Scanner(System.in);
  8.         boolean IsCorrect;
  9.         System.out.print("The program will determine whether the circle fits into the
  10.                          square.\n");
  11.         System.out.print("Enter radius: ");
  12.         do
  13.         {
  14.             IsCorrect = false;
  15.             try {
  16.                 radius = Integer.parseInt(in.next());
  17.             }
  18.             catch (NumberFormatException e) {
  19.                 System.out.print("Incorrect value. Enter the number: ");
  20.                 IsCorrect = true;
  21.             }
  22.             if ((!IsCorrect) && (radius == 0) || (radius < 0))
  23.             {
  24.                 System.out.print("Incorrect value. Enter the number: ");
  25.                 IsCorrect = true;
  26.             }
  27.         } while (IsCorrect);
  28.         System.out.print("Enter side: ");
  29.         do
  30.         {
  31.             IsCorrect = false;
  32.             try {
  33.                 side = Integer.parseInt(in.next());
  34.             }
  35.             catch (NumberFormatException e) {
  36.                 System.out.print("Incorrect value. Enter the number: ");
  37.                 IsCorrect = true;
  38.             }
  39.             if ((!IsCorrect) && (side == 0) || (side < 0))
  40.             {
  41.                 System.out.print("Incorrect value. Enter the number: ");
  42.                 IsCorrect = true;
  43.             }
  44.         } while (IsCorrect);
  45.         in.close();
  46.         if (radius * 2 < side)
  47.             System.out.print("Fit in.\n");
  48.         else
  49.             System.out.print("Not fit in.\n");
  50.     }
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement