Given two integers a and b, your task is to calculate :-
a+b
a-b
ab
a/b solve in java language.
Answers
Answer:
int a, b;
System.out.println(a+b);
System.out.println(a-b);
System.out.println(a*b);
System.out.println(a/b);
Explanation:
Answer:
The answer to the given question is explained in the explanation.
Explanation:
Enter two integers as input. Now choose from the suggested options to perform various operations on a given integer.
Below is the Java source code for calculating the sum, multiplication, division, and subtraction of two numbers.
import java.util.Scanner;
public class Arithmetic_operation
{
public static main (String [] args)
{
int m, n, opt, add, sub, mul;
double split;
scanner s = new scanner (System.in);
System.out.print("Enter the first digit:");
m = s.nextInt();
System.out.print("Enter the second number:");
n = s.nextInt()
while(true)
{
System.out.println("Enter 1 to add numbers");
System.out.println("Enter 2 to subtract numbers");
system outputprintln("Enter 3 to multiply");
System.out.println("Enter 4 to divide");
System.out.println("Enter 5 to exit");
opts = s.nextInt();
switch (optional)
{ for
1: Add
= a + b;
System.out.println("Result:"+add);
rest;
Case 2:
sub = a-b;
System.out.println("Result:"+sub);
rest;
Case 3:
mul = a*b;
System.out.println("Result:"+mul);
rest;
Case 4:
Case = (double)a/b ;
System.out.println("result:"+div);
rest;
Case 5:
System.exit(0);
}
}
}
}
#SPJ2