** Question:**** **

#### Write a java program that performs Addition, Subtraction, Multiplication, Division & Modulus like a simple calculator.

** Output Sample: **

1 2 3 4 5 6 7 |
Enter two values: 10 5 Addition: 15.0 Subtraction: 5.0 Multiplication: 50.0 Division: 2.0 Modulus: 0.0 |

** Source Code: **

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import java.util.Scanner; public class Calculator { public static void main(String[] args) { //variable declaration double a, b, addition, subtraction, multiplication, division, modulus; //object creation & get input from the user System.out.println("Enter two values: "); Scanner sc = new Scanner(System.in); a = sc.nextDouble(); b = sc.nextDouble(); //calculation mathematics term here addition = a + b; subtraction = a - b; multiplication = a * b; division = a / b; modulus = a % b; //print final output System.out.println("Addition: " + addition); System.out.println("Subtraction: " + subtraction); System.out.println("Multiplication: " + multiplication); System.out.println("Division: " + division); System.out.println("Modulus: " + modulus); } } |