Question 2.6: Write a Java program to print the sum (addition), multiply, subtract, divide and remainder of two numbers.
Test Data:
Input first number: 125
Input second number: 24
Expected Output:
125 + 24 = 149
125 - 24 = 101
125 x 24 = 3000
125 / 24 = 5
Solution:
package com.company;
import java.util.Scanner;
public class lab2problem06{
public static void main(String[] args)
{
Scanner Obj =new Scanner(System.in);
System.out.println("Input fist number: ");
int n = Obj.nextInt();
System.out.println("Input second number:");
int m = Obj.nextInt();
int z = n+m;
int mi = n-m;
int i = n*m;
float d =(float) n/m;
System.out.println(n + " + " + m + " = "+ z);
System.out.println(n + " - " + m + " = "+ mi);
System.out.println(n + " x " + m + " = "+ i);
System.out.println(n + " / " + m + " = "+ d);
}
}