master
dima 2024-11-04 20:01:08 +03:00
parent 5745de5bab
commit f2b2013249
1 changed files with 25 additions and 22 deletions

View File

@ -1,3 +1,4 @@
import javax.swing.*;
import java.util.Scanner; import java.util.Scanner;
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or //TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
@ -6,34 +7,36 @@ public class Main {
public static void main(String[] args) { public static void main(String[] args) {
Scanner a = new Scanner(System.in); Scanner scanner = new Scanner(System.in);
int number1 = a.nextInt(); int number1 = scanner.nextInt();
String sing = a.next(); String operation = scanner.next();
int number2 = a.nextInt(); int number2 = scanner.nextInt();
System.out.print("Ответ:"); System.out.print("Ответ:");
if (":" .equals(sing) && number2 != 0 ) { if (":".equals(operation)) {
float sum = (float) number1 / (float) number2; if (number2 != 0) {
System.out.println(sum); float division = (float) number1 / (float) number2;
System.out.println(division);
} else {
System.out.println("На 0 делить нельзя");
}
}
{
if ("+".equals(operation)) {
int addition = number1 + number2;
System.out.println(addition);
} }
if (":".equals(sing) && number2 == 0) { if ("-".equals(operation)) {
System.out.println("на ноль делить нельзя"); int subtraction = number1 - number2;
System.out.println(subtraction);
} }
if ("+" .equals(sing)) { if ("*".equals(operation)) {
int sum = number1 + number2; int multiplication = number1 * number2;
System.out.println(sum); System.out.println(multiplication);
} }
if ("-" .equals(sing)) {
int sum = number1 - number2;
System.out.println(sum);
}
if ("*" .equals(sing)) {
int sum = number1 * number2;
System.out.println(sum);
} }
} }
} }