Computer Science, asked by joydeepshubhadeep, 3 months ago

wap to print two number print sum subtraction division and multiplication using scanner class in JAVA (BLUE J application)​

Answers

Answered by BrainlyProgrammer
9

Answer:

import java.util.*;

class num{

public static void main (String ar[]){

Scanner sc=new Scanner(System.in);

System.out.println("Enter two numbers");

int a=sc.nextInt();

int b=sc.nextInt();

System.out.println("Enter operator to perform operations");

System.out.println("'+' for addition\n'-' for subtraction\n'/' for division\n'*' for multiplication");

char ch=sc.next().charAt(0);

switch(ch){

case '+': System.out.println("Sum="+(a+b)); break;

case '-': System.out.println("Difference="+(Math.abs(a-b))); break;

case '/': System.out.println("Division="+((b!=0)?(a/b):"Division by zero not allowed")); break;

case '*': System.out.println("Product="+(a*b));break;

default:System.out.println("Invalid Choice");

}

}

}

Required Output Attached

Attachments:
Similar questions