In: Computer Science
in java
Write an application that gets two numbers from the user and prints the sum, product, difference and quotient of the two numbers in a GUI.
import javax.swing.JOptionPane;
public class SampleGUI{
public static void main (String args[]){
int a,b, sum, product, difference, quotient;
String aVal, bVal;
//Getting the inputs from Java Dialog box
aVal = JOptionPane.showInputDialog("Enter first Integer:");
bVal = JOptionPane.showInputDialog("Enter second Integer:");
a = Integer.parseInt(aVal);
b = Integer.parseInt(bVal);
//Calculating the the sum, product, difference and quotient
sum = a+b ;
product = a*b;
difference = a-b;
quotient = a/b;
//Printing out the result using java Dialog box
JOptionPane.showMessageDialog(null, "The Sum of "+a+" and "+b+ " is " + sum+ "\nThe Product of "+a+" and "+b+ " is " + product+ "\nThe Difference of "+a+" and "+b+ " is " + difference+"\nThe Quotient of "+a+" and "+b+ " is " + quotient);
}
}
Output: