Add, Subtract, Multiply, Divide And Find Mod Of Two Numbers | Java Programs

Output:

*** Add, Subtract, Multiply, Divide ***

Enter first number: 9
Enter second number: 3
9 + 3 = 12
9 - 3 = 6
9 x 3 = 27
9 / 3 = 3
9 mod 3 = 0

Click Here For Java Online Compiler

Solution:

import java.util.Scanner;

public class AddSubtractMultiplyDivide {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("*** Add, Subtract, Multiply, Divide ***" + "\n");
        System.out.print("Enter first number: ");
        int num1 = scanner.nextInt();

        System.out.print("Enter second number: ");
        int num2 = scanner.nextInt();

        System.out.println(num1 + " + " + num2 + " = " + (num1 + num2));

        System.out.println(num1 + " - " + num2 + " = " + (num1 - num2));

        System.out.println(num1 + " x " + num2 + " = "+ (num1 * num2));

        System.out.println(num1 + " / " + num2 + " = " + (num1 / num2));

        System.out.println(num1 + " mod " + num2 + " = "+ (num1 % num2));
    }
}
Share This :

Related Post



sentiment_satisfied Emoticon