~/ 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/8fa37489-d406-4464-b339-c068afe9014a/flashcard utf-8 LF