Loading

Program for calculator operations:                                                                                                

package quipoin.javaeasyprograms;
import java.util.Scanner;

public class Calculator {
	public static double getCalculation(double a, double b, int c) {
		switch (c) {
		case 1:
			return a + b;
		case 2:
			return a - b;
		case 3:
			return a * b;
		case 4:
			return a / b;
		case 5:
			return a % b;
		default:
			System.out.println("wrong input");
		}
		return -1;

	}

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		System.out.println("Enter the value of a and b:");
		int a = sc.nextInt();
		int b = sc.nextInt();
		System.out.println("Enter 1 for Addition:\n" + 
		"Enter 2 for Substraction:\n" + 
		"Enter 3 for Multiplication:\n"+ 
		"Enter 4 for Division:\n" + 
		"Enter 5 for Modulus:");
		int c = sc.nextInt();
		System.out.println(getCalculation(a, b, c));
		sc.close();
	}
}

Output:

Enter the value of a and b:
5
2
Enter 1 for Addition:
Enter 2 for Substraction:
Enter 3 for Multiplication:
Enter 4 for Division:
Enter 5 for Modulus:
4
2.5