Hey,
I don't understand why
else if ((n1 == n2) || (n2 == n3)) {
midNum = n2;
}
else if (n1 == n3) {
midNum = n3;
}
is not returing the same number. It is always returning 0. It doesn't work with 4 3 3 or 3 4 3 but it strangly will work with 3 3 4. I've tried to look through other answers to see if someone has had the same problem and they did but the help they got from the community just gave different ways to solve the problem entirely (for example using arrays or *.math) and didn't explain why == didn't work. I know that sometimes there can be an object reference problem that will make it so it won't work, but I think in this case it should. I also tried to use n1.equals(n2), but it just threw an error. Any help would be greatly appreciated!package com.codegym.task.task04.task0441;
/*
Somehow average
*/
import java.io.*;
public class Solution {
public static void main(String[] args) throws Exception {
//write your code here
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int n1 = Integer.parseInt(reader.readLine());
int n2 = Integer.parseInt(reader.readLine());
int n3 = Integer.parseInt(reader.readLine());
int midNum = 0;
if (n1 > n2) {
if (n1 < n3) {
midNum = n1;
}
else if (n2 < n3) {
midNum = n3;
}
else if (n2 > n3){
midNum = n2;
}
}
else if (n2 > n1) {
if (n2 < n3) {
midNum = n2;
}
else if (n1 > n3) {
midNum = n1;
}
else if (n1 < n3) {
midNum = n3;
}
}
else if (n3 < n1) {
if (n3 < n2) {
midNum = n1;
}
}
else if ((n1 == n2) || (n2 == n3)) {
midNum = n2;
}
else if (n1 == n3) {
midNum = n3;
}
System.out.println(midNum);
}
}