Write a Java program to print the sum, multiply, subtract, divide and remainder of two numbers
Program
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int num1,num2;
Scanner in = new Scanner(System.in);
System.out.print("Input 1st number: ");
num1 = in.nextInt();
System.out.print("Input 2nd number: ");
num2 = in.nextInt();
System.out.println("Addition of two numbers: " + num1 + " + " + num2 + " = " + (num1 + num2));
System.out.println("subtraction of two numbers: " +num1 + " - " + num2 + " = " + (num1 - num2));
System.out.println("Multiplication of two numbers: "+ num1 + " x " + num2 + " = " + (num1 * num2));
System.out.println("Division of two numbers: " + num1 + " / " + num2 + " = " + (num1 / num2));
System.out.println("Remainder of two numbers: "+ num1 + " mod " + num2 + " = " + (num1 % num2));
}
}
Output:
Input 1st number: 12
Input 2nd number: 12
Addition of two numbers: 12 + 12 = 24
subtraction of two numbers: 12 - 12 = 0
Multiplication of two numbers: 12 x 12 = 144
Division of two numbers: 12 / 12 = 1
Remainder of two numbers: 12 mod 12 = 0