I have two separate programs and don\'t have my element program to display it. C
ID: 3647157 • Letter: I
Question
I have two separate programs and don't have my element program to display it. Can you put it in a Java program run it and display the outputs on here for me?Program 1
public class JavaProg
{
public static void main (String[] args)
{
int num1, num2, num3;
String input;
//accept user input
input = JOptionPane.showInputDialog("Please enter integer 1.");
num1 = Integer.parseInt(input);
input = JOptionPane.showInputDialog("Please enter integer 2.");
num2 = Integer.parseInt(input);
input = JOptionPane.showInputDialog("Please enter integer 3.");
num3 = Integer.parseInt(input);
//calculate sum,product,average
int sum = (num1 + num2 + num3);
int product = (num1 * num2 * num3);
double average = (sum / 3.0);
//calculate largest using math.max function
int largest = Math.max(num1, Math.max(num2, num3));
//calculate smallest number using math.max function
int smallest = Math.min(num1, Math.min(num2, num3));
}
}
Program 2
import javax.swing.JOptionPane;
public class JavaProg
{
public static void main (String[] args)
{
int num1, num2, num3;
String input;
//accept user input
input = JOptionPane.showInputDialog("Please enter integer 1.");
num1 = Integer.parseInt(input);
input = JOptionPane.showInputDialog("Please enter integer 2.");
num2 = Integer.parseInt(input);
input = JOptionPane.showInputDialog("Please enter integer 3.");
num3 = Integer.parseInt(input);
//calculate sum,product,average
int sum = (num1 + num2 + num3);
int product = (num1 * num2 * num3);
double average = (sum / 3.0);
//calculate largest using math.max function
int largest = Math.max(num1, Math.max(num2, num3));
//calculate smallest number using math.max function
int smallest = Math.min(num1, Math.min(num2, num3));
String avg = String.format("%.2f",average);
JOptionPane.showMessageDialog(null, "sum = " + sum + " product = " + product + " average = " + avg + " Smallest = " + smallest + " Largest = " + largest);
}
}
Explanation / Answer
Program takes 3 numbers and outputs 1) Sum of the numbers 2) Product of the numbers 3) Average of the numbers 4) Largest number 5) Smallest Number
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.