Learn Java: A program that accepts 2 integer values and 1 double value using JOption class

Copy the codes below and paste into your compiler. I used eclipse. Your Class name should be same as your file name.

// Write a program that accepts 2 integer values and 1 double value from //the keyboard using the JOption class; then compute the sum of the values. import javax.swing.JOptionPane; public class ClassSample3 { public static void main(String[] args) { String num1, num2, num3; int a,b; double c, sum, average; num1 = JOptionPane.showInputDialog(null, "Enter an Integer Value"); a = Integer.parseInt(num1); num2 = JOptionPane.showInputDialog(null, "Enter Second Integer Value"); b = Integer.parseInt(num2); num3 = JOptionPane.showInputDialog(null, "Enter a Double Value"); c = Double.parseDouble(num3); // Compute Sum and Average sum = a+b+c; average = (sum / 3); JOptionPane.showMessageDialog(null, "The sum is "+ sum +" \n The average is "+ average, "Answer", JOptionPane.PLAIN_MESSAGE); } }

If you encounter(ed) any error while compiling, Contact me here or leave a comment below. I'll get back to you.
Next PostNewer Post Previous PostOlder Post Home

0 comments:

Post a Comment