Modify the Java application from program 1. The new version of the program will use JOptionPanes for input and output. Use String.format("%.2f", doubleVariable) to create a string representation with two digits following the decimal point.
import javax.swing.JOptionPane;
public class numbers
{
public static void main( String[] args )
{
String st;
int largest, smallest;
double average, sum=0, product=1;
int[] num = new int[3];
for( int i = 0; i < 3; i++)
{
st = JOptionPane.showInputDialog( "Enter the number: " );
num[i] = Integer.parseInt( st );
sum = sum + num[i];
product = product * num[i];
}
average = sum / 3;
if(num[0] < num[1] && num[0] < num[2] )
smallest = num[0];
else if(num[1] < num[0] && num[1] < num[2] )
smallest = num[1];
else
smallest = num[2];
if(num[0] > num[1] && num[0] > num[2] )
largest = num[0];
else if(num[1] > num[0] && num[1] > num[2] )
largest = num[1];
else
largest = num[2];
System.out.println("The sum of three numbers is " + sum);
System.out.println("The product of three numbers is " + product);
System.out.println("The average of three numbers is " + average);
System.out.println("The largest of three numbers is " + largest);
System.out.println("The smallest of three numbers is " + smallest);
}
}