Change Summation Integers problem to Finding the minimum problem. Move System.out.print statements, displaying results inside the methods, making all your methods VOID.
Change Summation Integers problem to Finding
the minimum problem. Move System.out.print statements, displaying results inside the methods, making all your methods VOID.
The code to implement the requirements in Java language is as follows:
import java.io.*;
import java.util.*;
public class MinimumNum {
//Function to find the minimum of all numbers
//Return type is void
public static void min_num(int... arr){
//Initializing the mon variable with first number of the array
int min = arr[0];
for(int i = 0; i< arr.length; i++){
//If minimum number is greater than the current array value then update min variable
if(min > arr[i])
min = arr[i];
}
//Display the result
System.out.println("The minimum number is " + min);
}
public static void main(String[] args) {
//Calling the function with varied number of arguements
min_num(20, 10);
min_num(6, 4, 8);
min_num(18, 22, 15, 28);
}
}
Step by step
Solved in 2 steps with 1 images