From f2b20132496510cab2fd09482e92b0d01efae565 Mon Sep 17 00:00:00 2001 From: dima Date: Mon, 4 Nov 2024 20:01:08 +0300 Subject: [PATCH] fixes --- src/Main.java | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/src/Main.java b/src/Main.java index 7d8ffc8..5dbd8ac 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,3 +1,4 @@ +import javax.swing.*; import java.util.Scanner; //TIP To Run code, press or @@ -6,34 +7,36 @@ public class Main { public static void main(String[] args) { - Scanner a = new Scanner(System.in); - int number1 = a.nextInt(); - String sing = a.next(); - int number2 = a.nextInt(); + Scanner scanner = new Scanner(System.in); + int number1 = scanner.nextInt(); + String operation = scanner.next(); + int number2 = scanner.nextInt(); System.out.print("Ответ:"); - if (":" .equals(sing) && number2 != 0 ) { - float sum = (float) number1 / (float) number2; - System.out.println(sum); + if (":".equals(operation)) { + if (number2 != 0) { + float division = (float) number1 / (float) number2; + System.out.println(division); + } else { + System.out.println("На 0 делить нельзя"); + } } + { - if (":".equals(sing) && number2 == 0) { - System.out.println("на ноль делить нельзя"); - } + if ("+".equals(operation)) { + int addition = number1 + number2; + System.out.println(addition); + } - if ("+" .equals(sing)) { - int sum = number1 + number2; - System.out.println(sum); - } + if ("-".equals(operation)) { + int subtraction = number1 - number2; + System.out.println(subtraction); + } - if ("-" .equals(sing)) { - int sum = number1 - number2; - System.out.println(sum); - } - - if ("*" .equals(sing)) { - int sum = number1 * number2; - System.out.println(sum); + if ("*".equals(operation)) { + int multiplication = number1 * number2; + System.out.println(multiplication); + } } } } \ No newline at end of file