Answer:
Below is the program TwoSmallest.java with each step explanation in form of comments.
public class TwoSmallest { // class definition
//main class having string args as a parameter
public static void main(String[] args)
{
if (args.length < 2)
{ //string length must not be less than 2 for proceeding
System.out.println("Please provide double values as command line arguments");
}
else {
// first two entries of string are checked for min1 and min2 and stored in variables with data type double
double min1 = Double.parseDouble(args[0]), min2 = Double.parseDouble(args[1]), num;
//when min1 will be greater than min2 it will be stored temporary in variable temp having data type double
if (min1 > min2) {
double temp = min1;
min1 = min2;
min2 = temp; //value of temp will be stored in min2
}
//loop will check for each entry remaining until the last character of string
for (int i = 2; i < args.length; i++) {
num = Double.parseDouble(args[i]);
if (num < min1) {
min2 = min1;
min1 = num;
} else if (num < min2) {
min2 = num;
}
}
//min1 will give the 1st minimum number and min2 will give 2nd minimum.
System.out.println(min1);
System.out.println(min2);
//both characters will be printed in sequence
}
}
}