Computer Science, asked by manansrivastava13aug, 5 hours ago

Write a program to enter an operator and perform the arithmetic operations (+, -, *, /and %) according to the operator entered. in java

Answers

Answered by CoderRishav
0

Answer:

import java.util.Scanner;

public class Opr

{

public static void main () {

Scanner in = new Scanner(System.in);

char inp = in.next().charAt(0);

switch(inp)

{

case '+':

int one = in.nextInt();

int two = in.nextInt();

System.out.println(one + two);

break;

case '-':

int one = in.nextInt();

int two = in.nextInt();

System.out.println(one - two);

break;

case '*':

int one = in.nextInt();

int two = in.nextInt();

System.out.println(one * two);

break;

case '/':

float one = in.nextInt();

float two = in.nextInt();

System.out.println(one / two);

break;

case '%':

int one = in.nextInt();

int two = in.nextInt();

System.out.println(one % two);

break;

default:

System.out.print("No more options");

}

}

}

Similar questions