Computer Science, asked by laliteshwarkumar1965, 12 hours ago

WAP a Java program using if else if to input 2 numbers and an arithmetic operator and perform arithmetic operation on two numbers according to operator​

Answers

Answered by r30499699
0

// Java program to enter two numbers and perform all arithmetic operations

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

System.out.println("Enter any two positive integer numbers:");

// Reading data using readLine

int p = in.nextInt();

int q = in.nextInt();

int sum, sub, mul, mod;

float div;

sum = p + q;

sub = p - q;

mul = p * q;

div = p / q;

mod = p % q;

System.out.println("\nSUM " + p + " + " + q + " = " + sum);

System.out.println("DIFFERENCE " + p + " - " + q + " = " + sub);

System.out.println("PRODUCT " + p + " * " + q + " = " + mul);

System.out.println("QUOTIENT " + p + " / " + q + " = " + div);

System.out.println("MODULUS " + p + " % " + q + " = " + mod);

}

}

Output :

Enter any two positive integer numbers:

5

8

SUM 5 + 8 = 13

DIFFERENCE 5 - 8 = -3

PRODUCT 5 * 8 = 40

QUOTIENT 5 / 8 = 0.0

MODULUS 5 % 8 = 5

Similar questions