Categories: TOP CONTENT

WAJP to create a function that accepts two numbers and an operator as arguments and returns the resultant value.

import java.util.*;
class function
{
public static double gen(double i1,double i2,char c1)
{
double i3=0;
switch(c1)
{
case ‘+’:i3=i1+i2;break;
case ‘-‘:i3=i1-i2;break;
case ‘*’:i3=i1*i2;break;
case ‘/’:i3=i1/i2;break;
case ‘%’:i3=i1%i2;break;
}
return i3;
}
public static void main()
{
Scanner in=new Scanner(System.in);
System.out.println(“Enter two numbers and any\nopertaor \n+\n-\n*\n/\n%”);
double i1=in.nextDouble();
double i2=in.nextDouble();
in.nextLine();
char c=(in.nextLine()).charAt(0);
double call=gen(i1,i2,c);
System.out.println(“Result is = “+call);
}
}

Lavi Thakur

Recent Posts

How to make money as a Beginner Coder in 2025

Making money as a coder in 2025 is not much of a big or tough…

1 year ago

Lloyds Technology Centre : A Concise Guide

Lloyds Technology Centre, A tech and data company located in Hyderabad, India. They are  part of…

1 year ago

How to Increase Height at Any Age

How to Increase Height at Any Age Rise Above: How to Increase Height at Any…

1 year ago

The Hidden Beauty of Karrukha Wood: A Rare Masterpiece from Nature

In the fast-paced digital world, we often forget the timeless beauty that nature offers. Today,…

1 year ago

Top 10 Deadliest Kicks in Martial Arts [2024]

Top 10 Deadliest Kicks in Martial Arts: Master the Art of Knockouts Martial arts is…

1 year ago

How to Optimize Battery Life of Your Smartphone

How to Optimize Battery Life of Your Smartphone: Tips and Tricks for Prolonging Battery Health…

1 year ago