Java > Warmup-1 > intMax (CodingBat Solution)

Problem:

Given three int values, a b c, return the largest.

intMax(1, 2, 3) → 3
intMax(1, 3, 2) → 3
intMax(3, 2, 1) → 3


Solution:

public int intMax(int a, int b, int c) {
  int temp1 = Math.max(a,b);
  int temp2 = Math.max(temp1, c);
  return temp2;
}

1 comment:

  1. public int intMax(int a, int b, int c) {
    return Math.max(Math.max(a, b), c);
    }

    ReplyDelete