public class MinimumNumber{
public static void main(String[] args){
int[] arr=new int[]{2,3,4,1};
int min=arr[0];
for(int i=0;i<arr.length;i++){
if(arr[i]<min){
min=arr[i];
}
}
System.out.println("Minimum Number in array:"+min);
}
}
private static int findMin(int[] array) {
int min = array[0];
for(int i=1;i<array.length;i++) {
if(min > array[i]) {
min = array[i];
}
}
return min;
}
int /*OR*/ double /*OR*/ float[] array_of_numbers = {/*Whatever values you want*/}
/*For this example we're just using a regular integer array*/
int min = array_of_numbers[0]; /*Important to initialise the first value!!!!*/
for (int i = 0; i < array_of_numbers.length; i++) {
if(array_of_numbers[i] < min) { /* So now we can make the comparison*/
min = array_of_numbers[i]; /* If smaller, make it the new minimum*/
}
}
System.out.println("Minimum value in array: " + min)
public static void main(String[] args) {
int[] xr = {2, 4, 1, 3, 7, 5, 6, 10, 8, 9};
//find maximum value
int max = xr[0];
for (int i = 0; i < xr.length; i++) {
if (xr[i] > max) {
max = xr[i];
}
}
//find minimum value
int min=xr[0];
for (int i = 0; i <xr.length ; i++) {
if (xr[i]<min){
min=xr[i];
}
}
System.out.println("max: "+max);
System.out.println("min: "+min);
}