Write a JAVA program that performs all mathematical operations on two variables.

 public class MathemacticaOperations{

public static void main(String[] args) { 

      int num1 = 5, num2 = 10;

      int sum;

      int difference;

      int product;

      int quotient;

      int modulo;

      sum = num1 + num2;

      difference = num1 - num2;

      product = num1 * num2;

      quotient = num1 / num2;

      modulo = num1 % num2;

         //print result to console

      System.out.println("Sum of these numbers: " +sum);

      System.out.println("Difference  of these numbers: " +difference);

      System.out.println("Product of these numbers: " +product);

      System.out.println("Quotient of these numbers: " +quotient);

      System.out.println("Modulo of these numbers: " +modulo);

      

   }

}

OUTPUT

Sum of these numbers: 15
Difference  of these numbers: -5
Product of these numbers: 50
Quotient of these numbers: 0
Modulo of these numbers: 5

1 comment: