~/ learn/ java-from-zero/ cards/ Methods & Encapsulation
1 of 19

Type a method that returns the larger of two ints

Type a method that returns the larger of two ints

Answer

public static int max(int a, int b) { return (a >= b) ? a : b; }

Every execution path returns an int. If any reachable path were missing a return, the compiler would reject it.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/544be74a-b662-4c43-b174-f6a925520872/flashcard utf-8 LF