Обновить Main.java

This commit is contained in:
VolkovaV 2025-11-22 16:09:26 +00:00
parent 4847144f8f
commit 472b422c6e

View File

@ -7,43 +7,65 @@ public class Main {
private int b; private int b;
private int sum; private int sum;
private int mult; private int mult;
private int delen;
private int vich;
Scanner scanner = new Scanner(System.in); Scanner scanner = new Scanner(System.in);
public void main(String[] args) { public void main(String[] args) {
while (true){ while (true) {
System.out.println("Введите 1 число: "); System.out.println("Введите 1 число: ");
int a = scanner.nextInt(); int a = scanner.nextInt();
System.out.println("Введите 2 число: "); System.out.println("Введите 2 число: ");
int b = scanner.nextInt(); int b = scanner.nextInt();
System.out.println("Введите нужное действие: \n 1.Сложение \n 2.Умножение \n "); System.out.println("Введите нужное действие: \n 1.Сложение \n 2.Умножение \n 3.Деление \n 4.Вычитание");
int des = scanner.nextInt(); int des = scanner.nextInt();
if (des == 1 ){ if (des == 1) {
int res = plus(a,b); int res = plus(a, b);
System.out.println("Результат: " + res); System.out.println("Результат: " + res);
break; break;
}else if (des == 2){ } else if (des == 2) {
int res = mult(a,b); int res = mult(a, b);
System.out.println("Результат: " + res); System.out.println("Результат: " + res);
break; break;
}else{ } else if (des == 3) {
System.out.println("Введите другое число 1 или 2 "); int res = delen(a, b);
System.out.println("Результат: " + res);
break;
} else if (des == 4) {
int res = vich(a, b);
System.out.println("Результат: " + res);
break;
} else {
System.out.println("Введите другое число 1, 2, 3 или 4 ");
} }
} }
} }
public static int plus(int a, int b){ public static int plus(int a, int b) {
int sum = a + b; int sum = a + b;
return sum; return sum;
} }
public static int mult (int a, int b){
public static int mult(int a, int b) {
int mult = a * b; int mult = a * b;
return mult; return mult;
} }
public static int delen(int a, int b) {
int delen = a / b;
return delen;
}
public static int vich(int a, int b) {
int vich = a - b;
return vich;
}
} }