~/ learn/ java-from-zero/ cards/ Defining & calling methods
1 of 4

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/9bf4ac62-e755-4d28-abb4-e97b84c794cb/flashcard utf-8 LF