So, this was my solution for this problem, and I feel I may have over complicated this a little bit. My output from entering 1,2,9,9 comes out as 1, which is incorrect. What I tried to do was break down all the logic required to both come up with a maximum number between the 4, and only display 1 input should two inputs be the max number.
So I suppose what I'm wondering is, if there is a simpler, cleaner way to do this problem, and if not, where I went wrong in my code. Thanks in advance for the help!
package com.codegym.task.task04.task0419;
/*
Maximum of four numbers
*/
import java.io.*;
public class Solution {
public static void main(String[] args) throws Exception {
//write your code here
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int l1 = Integer.parseInt(read.readLine());
int l2 = Integer.parseInt(read.readLine());
int l3 = Integer.parseInt(read.readLine());
int l4 = Integer.parseInt(read.readLine());
Boolean a;
Boolean b;
Boolean c;
Boolean d;
Boolean e;
Boolean f;
Boolean a1;
Boolean b1;
Boolean c1;
Boolean d1;
Boolean e1;
Boolean f1;
Boolean a2;
Boolean b2;
Boolean c2;
Boolean d2;
Boolean e2;
Boolean f2;
Boolean g2;
{
if (l1 == l2)
a = true;
else if (l1 == l3)
b = true;
else if (l1 == l4)
c = true;
else if (l2 == l3)
d = true;
else if (l3 == l4)
e = true;
else if (l2 == l4)
f = true;
}
{
if ((a = true) && ((l1 > l3) && (l1 > l4)))
a1 = true;
else if ((b = true) && ((l1 > l2) && (l1 > l4)))
b1 = true;
else if ((c = true) && ((l1 > l2) && (l1 > l3)))
c1 = true;
else if ((d = true) && ((l2 > l1) && (l2 > l4)))
d1 = true;
else if ((e = true) && ((l3 > l1) && (l3 > l2)))
e1 = true;
else if ((f = true) && ((l2 > l3) && (l2 > l1)))
f1 = true;
else if (((f = true) || (e = true)) && ((l4 > l1) && (l4 > l2) && (l4 > l3)))
g2 = true;
}
{
if ((a = true) && (a1 = true))
a2 = true;
else if ((b = true) && (b1 = true))
b2 = true;
else if ((c = true) && (c1 = true))
c2 = true;
else if ((d = true) && (d1 = true))
d2 = true;
else if ((e = true) && (e1 = true))
e2 = true;
else if ((f = true) && (f1 = true))
f2 = true;
}
{if ((l1 > l2) && (l1 > l3) && (l1 > l4) || (a2 = true) || (b2 = true) || (c2 = true))
System.out.println(l1);
else if ((l2 > l3) && (l2 > l4) && (l2 > l1) || (d2 = true) || (f2 = true))
System.out.println(l2);
else if ((l3 > l2) && (l3 > l4) && (l3 > l1) || (e2 = true))
System.out.println(l3);
else if ((l4 > l2) && (l4 > l3) && (l4 > l1) || (g2 = true))
System.out.println(l4);}
}
}