import java.util.Arrays;
public class SmallestIntArray{
public static int getSmallest(int[] a){
Arrays.sort(a);
return a[0];
}
public static void main(String []args){
int a[] = {1,2,3,4,5,0,1};
System.out.println(getSmallest(a));
}
}
The method getSmallest takes one arguement, an array of integers. The integers are then sorted in ascending order (smallest number first) then we return the first integer in the array.
import java.util.Arrays;
public class SmallestIntArray{
public static int getSmallest(int a, int b, int c, int d, int e, int f){
int ar[] = {a, b, c, d, e, f};
Arrays.sort(ar);
return ar[0];
}
public static void main(String []args){
System.out.println(getSmallest(1,2,3,4,5,0));
}
}
The method getSmallest takes 6 integers as arguements and then puts them into an array. We then sort that array in ascending order and we get the smallest number by returning the first integer in the array.