logo image

Calculator Java program



A simple Calculator Java program shows you Sum, Subtraction, Multiplication and Division

import java.util.Scanner;

public class Calculator {
	
	public static void main(String[] args) {
		
		System.out.print("Enter first number: ");
		Scanner sc = new Scanner(System.in);
		int i = sc.nextInt();
		System.out.print("Enter second number: ");
		int j = sc.nextInt();
		sc.close();

		System.out.println("Sum value is:" + sum(i, j));
		System.out.println("Subtraction value is:" + subtraction(i, j));
		System.out.println("Multiplication value is:" + multiplication(i, j));
		System.out.println("Division value is:" + division(i, j));

	}

	public static int sum(int a, int b) {
		int result = a + b;
		return result;
	}

	public static int subtraction(int a, int b) {
		int result = a - b;
		return result;
	}

	public static int multiplication(int a, int b) {
		int result = a * b;
		return result;
	}

	public static int division(int a, int b) {
		return a / b;

	}

}

Output

 Enter first number: 40
 Enter second number: 20
 Sum value is:60
 Subtraction value is:20
 Multiplication value is:800
 Division value is:2