In Java, Write a small program that gets some numbers as command line arguments and finds the minimum of those numbers. You can assume that the user will provide some command line arguments when running the program (so you don’t have to worry about what to do if the user doesn’t provide any arguments -- that won’t happen). Also, you can assume that all the command line arguments will be floating-point numbers, i.e., numbers with a decimal point, like 8.25.
Explanation:
Here is the code which takes the command line arguments as soe float values and then finds the minimum out of those given float values and print to the console output.
Code:
public class Main
{
public static void main(String[] args) {
float min = Float.MAX_VALUE;
for(int i=0; i<args.length;
i++)
{
float num =
Float.parseFloat(args[i]);
if (num<min)
min = num;
}
System.out.println("Minimum is:
"+min);
}
}
Command line args given:
3.45 7.8 8.35 1.2
Output:
PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!
PLEASE COMMENT IF YOU NEED ANY HELP!
Get Answers For Free
Most questions answered within 1 hours.