about | help | code help+videos | done | prefs |
getSmallest3
public int getSmallest3(int[] nums)
public int getSmallest3(int[] nums) { int smallest = nums[0]; if (nums[1] < smallest) { smallest = nums[1]; } if (nums[2] < smallest) { smallest = nums[2]; } return smallest; }Below is how you would do the same thing using Math.min(). public int getSmallest3(int[] nums) { int smallest = Math.min( nums[0], nums[1] ); smallest = Math.min( smallest, nums[2] ); return smallest; } getSmallest3([5, 10, 15]) → 5 getSmallest3([15, 10, 5]) → 5 getSmallest3([3, 6, 9]) → 3 ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 1
Copyright Nick Parlante 2017 - privacy