~/ 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/e17f6566-5fd0-4dc0-a6b0-8b23459362fb/flashcard utf-8 LF