Homework : Largest Of Three

if ( first > second && first > third); {
System.out.println(first);
} else if ( second > first && second > third); {
System.out.println(second);
} else (third > first && third > second); {
System.out.println(third);
}

i have been trying alot of ways to solve this but i am unable to. I have tried to frame the mathematical condition into code but i get the error that “line 3 is not a statement”

Try to delete the semi-colon before the big brackets, and revise your code like the following.

void largeOfThree(int first, int second, int third) {
  if (first > second && first > third) {
    System.out.println(first);
  } else if (second > first && second > third) {
    System.out.println(second);
  } else if (third > first && third > second) {
    System.out.println(third);
  }
}
largeOfThree(1, 2, 3);
largeOfThree(1, 1, 2);
largeOfThree(1, 1, 1); // this one should print 1, but it doesn't work.

I tried running the code without the semi-colon and without the first line that says “void” & the last three lines of “largestofthree” and yet the result shows “stopped after finding 1 failure”

PS we are using double variables here.

Thanks alot for the prompt reply Yao!!

1 Like