I am a beginner with Java (only about a month into Java). I need to write a program that reads 5 integers and then prints out the largest. I have done it, however I was told there is a more efficient way of doing it,how can i achieve that? Any advice will be appreciated!
Scanner input = new Scanner(System.in);
int A = input.nextInt();
int B = input.nextInt();
int C = input.nextInt();
int D = input.nextInt();
int E = input.nextInt();
if (A > B && A > C && A > D && A > E)
{
System.out.println(A);
}
if (B > A && B > C && B > D && B > E)
{
System.out.println(B);
}
if (C > A && C > B && C > D && C > E)
{
System.out.println(C);
}
if (D > A && D > B && D > C && D > E)
{
System.out.println(D);
}
if (E > A && E > B && E > C && E > D)
{
System.out.println(E);
}