
Part one In a Java program, create an array of 5 doubles. Have the user input values into these array items inside a loop using JOptionPane. Using the loop, calculate the sum and average of the 5 numbers and output this using JOptionPane.
Part two Same as above, only have a second loop (enhanced for loop) do the summing to calculate the average.
Part three Write a simple program that will have an integer division inside a try block followed by a catch block with an appropriate argument type. Inside the catch block, output a message saying that division by zero is not allowed. Run this code with and without the denominator being zero. When the denominator is not zero, output a message displaying the calculated ratio.

import javax.swing.JOptionPane;
public class FiveDoubles
{
/**
* @param args
*/
public static void main(String[] args)
{
String input;
double data[] = new double[5];
double sum = 0, average;
for ( int i = 0; i < data.length; i++ )
{
input = JOptionPane.showInputDialog("INPUT A NUMBER");
data[i] = Double.parseDouble(input);
}
for ( int j = 0; j < data.length; j++)
sum += data[j];
average = sum/data.length;
String output = "Value/n";
for (int k = 0; k < data.length; k++)
output += data[k] + "\n";
JTextArea outputArea = new JTextArea();
outputArea.setText(output);
JOptionPane.showmessageDialog(null, outputArea, "SumAverage",
JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.