This is JAVA
Write the method findMin that will return the smallest number in an array of integers.
Examples:
findMin({29,2,32,12}) -> 2
public int findMin(int[] numbers) {
}
public int findMin(int[] numbers) { int min = numbers[0]; for (int i = 0; i < numbers.length; i++) { if (numbers[i] < min) min = numbers[i]; } return min; }
public class FindMin { public int findMin(int[] numbers) { int min = numbers[0]; for (int i = 0; i < numbers.length; i++) { if (numbers[i] < min) min = numbers[i]; } return min; } public static void main(String[] args) { System.out.println(new FindMin().findMin(new int[] {4, 9, 2, 6, 3})); } }
Get Answers For Free
Most questions answered within 1 hours.