**Â Question:****Â **

#### Write a java program that performs addition, subtraction, multiplication, division using a method like output sample.

**Â Output Sample: Â Â **

1 2 3 4 5 6 |
Enter two values: 15 5 Addition: 20.0 Subtraction: 10.0 Multiplication: 75.0 Division: 3.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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
import java.util.Scanner; public class Calculator { public static void main(String[] args) { //variable initialization double num1, num2, addition, subtraction, multiplication, division; //input from the user System.out.print("Enter two values: "); Scanner sc = new Scanner(System.in); num1 = sc.nextDouble(); num2 = sc.nextDouble(); //methods declaration addition = performAddition(num1, num2); subtraction = performSubtraction(num1, num2); multiplication = performMultiplication(num1, num2); division = performDivision(num1, num2); //print the final output System.out.println("Addition: "+addition); System.out.println("Subtraction: "+subtraction); System.out.println("Multiplication: "+multiplication); System.out.println("Division: "+division); } //for addition method static double performAddition(double a, double b){ double result = a + b; return result; } //for subtraction method static double performSubtraction(double a, double b){ double result = a - b; return result; } //for multiplication method static double performMultiplication(double a, double b){ double result = a * b; return result; } //for division method static double performDivision(double a, double b){ double result = a / b; return result; } } |