BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int a= Integer.parseInt(reader.readLine());
int b= Integer.parseInt(reader.readLine());
int c= Integer.parseInt(reader.readLine());
if((a==b) && (b==c) && (a==c)){
System.out.println(b);
}else if(((a<b) &&(b<c) && (a<c)) ||((a<b) &&(b>c) && (a<c))) {
System.out.println(a);
}else if(((a<b) &&(b<c) && (a>c)) || ((a>b) &&(b<c) && (a<c))) {
System.out.println(c);
}else if(((a>b) &&(b>c) && (a>c)) ||((a<b) &&(b>c) && (a>c))) {
System.out.println(c);
}else if((a==b) && (b<c) || ((a==c) && (b>c))){
System.out.println(a);
}else if(((b==c) && (a>b)) || (b==c) && (a<b)) {
System.out.println(b);
}
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 a= Integer.parseInt(reader.readLine());
int b= Integer.parseInt(reader.readLine());
int c= Integer.parseInt(reader.readLine());
if((a==b) && (b==c) && (a==c)){
System.out.println(b);
}else if(((a<b) &&(b<c) && (a<c)) ||((a<b) &&(b>c) && (a<c))) {
System.out.println(a);
}else if(((a<b) &&(b<c) && (a>c)) || ((a>b) &&(b<c) && (a<c))) {
System.out.println(c);
}else if(((a>b) &&(b>c) && (a>c)) ||((a<b) &&(b>c) && (a>c))) {
System.out.println(c);
}else if((a==b) && (b<c) || ((a==c) && (b>c))){
System.out.println(a);
}else if(((b==c) && (a>b)) || (b==c) && (a<b)) {
System.out.println(b);
}
}
}
if(((a<b) &&(b<c) && (a<c)) ||((a<b) &&(b>c) && (a<c))) {
your code contains the correct way, you just need to remove the superfluous start with((a<b) &&(b<c) && (a<c))
... if a < b and b < c then a has to be < c, you do not need to check this anymore. But that condition does not give you any gain (except that b is in the middle:) ) therefore you check:((a<b) &&(b>c) && (a<c))
The same here, if a < b and a < c you know that a is the smallest but you additionally check if b > c ??? means you want to know the smallest just in the case if b < c like 1, 2, 3 but not 1, 3, 2 The way to check if a is the smallest of a, b, c is just to checkif (a < b && a < c) {
And there is a logical breach in line 22 -> this condition can never be evaluated to true if a < b and b < c then c is the biggest number of those three and a can not be > c There are some really nice approaches to find the middle number other that conditional branching. Just as a hint.