Answer the question
In order to leave comments, you need to log in
Why does it return default?
import java.util.Scanner;
public class TestConditions {
public static void main(String[] args) {
Conditions cond = new Conditions();
try (Scanner scanner = new Scanner(System.in)) {
System.out.println("Введите первое число:");
cond.setFirstChange(scanner.nextInt());
System.out.println("Введите второе число:");
cond.setSecondChange(scanner.nextInt());
System.out.println("Введите номер операции: 1.Умножение 2.Деление 3.Сложение");
cond.setThirdChange(scanner.nextInt());
cond.operation(cond.getFirstChange(), cond.getSecondChange(), cond.getThirdChange());
}
}
}
public class Conditions {
private int firstChange;
private int secondChange;
private int thirdChange;
public void setFirstChange(int a){
a = firstChange;
}
public void setSecondChange(int b){
b = secondChange;
}
public void setThirdChange(int c){
c = thirdChange;
}
public int getFirstChange(){
return firstChange;
}
public int getSecondChange(){
return secondChange;
}
public int getThirdChange(){
return thirdChange;
}
public void operation(int x, int y, int z) {
switch(z) {
case 1:
int res = x*y;
System.out.println(res);
break;
case 2:
int res1 = x/y;
System.out.println(res1);
break;
case 3:
int res2 = x+y;
System.out.println(res2);
break;
default:
System.out.println("Операция не определена");
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question