Q:

Write a Java Program to Perform Mathematical Operations

belongs to collection: Java Basic Solved Programs

0

Write a Java Program to Perform Mathematical Operations such as addition, subtraction, multiplication and division of any two number in Java Programming, you have to ask to the user to enter the two number and then perform the action accordingly.

Following Java Program ask to the user to enter the two number and perform the addition, subtraction, multiplication and division on the two entered number by the user and then display the result on the screen:

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

SOURCE CODE ::

import java.util.Scanner;
                 
public class mat_operations
{
    public static void main(String args[])
    {
       int a, b, res;
       Scanner scan = new Scanner(System.in);
           
       System.out.print("Enter Two Numbers : ");
       a = scan.nextInt();
       b = scan.nextInt();
           
       res = a + b;
       System.out.println("Addition = " +res);
           
       res = a - b;
       System.out.println("Subtraction = " +res);
           
       res = a * b;
       System.out.println("Multiplication = " +res);
           
       res = a / b;
       System.out.println("Division = " +res);
    }
}

OUTPUT ::

Enter Two Numbers : 34
79
Addition = 113
Subtraction = -45
Multiplication = 2686
Division = 0

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java Basic Solved Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a Java Program to Perform Mathematical Opera... >>
<< Write a Java Program to Print Pascal Triangle usin...