Calculating Product, sum, difference, and quotient of Five Integers

A simulation question is given to write an application using Java language that asks the user to enter five integers, obtains the numbers from the user and prints the product, sum, difference and quotient (division) of the numbers using the Java GUI (Graphics User Interface).

In  Java, user input is normally in form of strings and not integers; so when the user inputs an integer as a string, we need to convert it to its corresponding integer by calling the integer.parseInt() method.

We will also be importing the javax.swing.JOptionPane, which will be used be used for dialog boxes. in my tutorial on Comparing Two Integers in Java programming, i explained the usefulness of dialog box.



import javax.swing.JOptionPane;

public class Product{
  public static void main (String args[])
  {
    int r;
    int s;
    int t;
    int u;
    int v;
    int sum;
    int product;
    int difference;
    int division;
 
    String rVal; 
    String sVal;
    String tVal;
    String uVal;
    String vVal;
 
    rVal = JOptionPane.showInputDialog("Enter frist Integer:");
    sVal = JOptionPane.showInputDialog("Enter second Integer:");
    tVal = JOptionPane.showInputDialog("Enter third Integer:");
    uVal = JOptionPane.showInputDialog("Enter fourth Integer:");
    vVal = JOptionPane.showInputDialog("Enter fifth Integer:");
 
    r = Integer.parseInt(rVal);
    s = Integer.parseInt(sVal);
    t = Integer.parseInt(tVal);
    u = Integer.parseInt(uVal);
    v = Integer.parseInt(vVal);
 
    sum = r + s + t + u + v;
    product = r * s * t * u *v;
    difference = r -s -t - u - v;
    division = r / s/ t/u /v;
 
    JOptionPane.showMessageDialog(null, "The Sum is " + sum);
    JOptionPane.showMessageDialog(null, "The Product is" + product);
    JOptionPane.showMessageDialog(null, "The Difference is" + difference);
    JOptionPane.showMessageDialog(null, "The Quotient is" + division);
 
    System.exit(0);
  }
}

Comments

  1. 10cric login - Gold Casino
    10cric login. In 10cric this tutorial you will learn how to create a sportsbook account. 바카라사이트 This tutorial shows you how to create 1XBET a sport betting account.

    ReplyDelete
  2. Cool and I have a tremendous offer: How Long Renovate House kitchen remodel companies near me

    ReplyDelete

Post a Comment

Please feel free to comments if you have any ideas, questions and subjection concerning our post and programs

Popular posts from this blog

Body Mass Index Calculator In C

Adding two Integers in Java Application