Computer Science, asked by rayyansyed1224, 6 months ago

java progam to perform arithemetic operation​

Answers

Answered by vishali3943
2

Answer:

This program finds the sum of two, three and four numbers using method overloading. Here we have three methods with the same name add(), which means we are overloading this method. Based on the number of arguments we pass while calling add method will determine which method will be invoked.

To understand this program you should have the knowledge of following Core Java topic:

Java – Method Overloading

Example: Program to find the sum of multiple numbers using Method Overloading

First add() method has two arguments which means when we pass two numbers while calling add() method then this method would be invoked. Similarly when we pass three and four arguments, the second and third add method would be invoked respectively.

Answered by akshatsaxena2003
0

import java.util.*;

class xyz

{

public static void main (String args[ ])

{

int a=5,b=6;

int s,d,p,div;

Scanner sc=new Scanner(System.in);

System.out.println("Enter the operator");

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

switch(operator)

case '+':

s=a+b;

System.out.println(s);

break;

case '-':

d=a-b;...........

u have to use the same method and type till last case.

and after that.

write the default statement and the paranthases.

Similar questions