1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
baherus [9]
3 years ago
10

Create a function void process(char ch, int x, int y)- to accept an arithmetic operator (+,-./, in argum

Computers and Technology
1 answer:
saul85 [17]3 years ago
6 0

Answer:

The program is as follows:

import java.util.*;

public class Main{

   public static void process(char ch, int x, int y){

if(ch == '+'){

    System.out.print(x+y);  }

else if(ch == '-'){

    System.out.print(x-y);  }

else if(ch == '*'){

    System.out.print(x*y);  }

else if(ch == '/'){

    if(y!=0){

        double num = x;

        System.out.print(num/y);      }

    else{

        System.out.print("Cannot divide by 0");     } }

else{

    System.out.print("Invalid operator"); }

 }

public static void main(String[] args) {

 Scanner input = new Scanner(System.in);

 int x, y;

 char ch;

 System.out.print("Enter two integers: ");

 x = input.nextInt(); y = input.nextInt();

 System.out.print("Enter operator: ");

 ch = input.next().charAt(0);  

 process(ch,x, y);

}

}

Explanation:

The function begins here

   public static void process(char ch, int x, int y){

If the character is +, this prints the sum of both integers

<em> if(ch == '+'){</em>

<em>     System.out.print(x+y);  }</em>

If the character is -, this prints the difference of both integers

<em> else if(ch == '-'){</em>

<em>     System.out.print(x-y);  }</em>

If the character is *, this prints the product of both integers

<em> else if(ch == '*'){</em>

<em>     System.out.print(x*y);  }</em>

If the character is /, this prints the division of both integers.

<em> else if(ch == '/'){</em>

<em>     if(y!=0){</em>

<em>         double num = x;</em>

<em>         System.out.print(num/y);      }</em>

<em>     else{</em>

<em>This is executed if the denominator is 0</em>

<em>         System.out.print("Cannot divide by 0");     } }</em>

Invalid operator is printed for every other character

<em>else{</em>

<em>     System.out.print("Invalid operator"); }</em>

<em> </em> }

The main begins here

public static void main(String[] args) {

 Scanner input = new Scanner(System.in);

This declares both integers

 int x, y;

This declares the operator

 char ch;

Get input for both integers

<em>  System.out.print("Enter two integers: ");</em>

<em>  x = input.nextInt(); y = input.nextInt();</em>

Get input for the operator

<em>  System.out.print("Enter operator: ");</em>

<em>  ch = input.next().charAt(0);   </em>

Call the function

 process(ch,x, y);

}

}

You might be interested in
News writers get story leads from____.
Andrei [34K]
I believe the answer is B.Press releases! Hope this helps:)
4 0
3 years ago
Word-processing,spreadsheets, databases, and desktop publishing are all types of _______?
vichka [17]

Answer:

software

Explanation:

5 0
3 years ago
Read 2 more answers
How can I write an assignment statement that stores the character 'X' in a variable ch?
Gre4nikov [31]

Answer:

In C++ we can assign a character to the variable by using the below statement.

ch='X';

Explanation:

The complete program for assigning a character to the variable is given as

#include<iostream>

#include <conio.h>

using namespace std;

main()

{

char ch;

ch= 'X';

cout<<"output of variable Ch ="<<ch;

getch();

}

In above program Char is the data type used for character type variables. ch= 'X' stores X in ch. Then output will shown through cout.

5 0
4 years ago
Which 2 tools are useful to remote employees and coworkers.
dsp73
Two big useful tools are one, File Storage tools, and two, Project Management Tools.
5 0
3 years ago
Your company is implementing a wireless network and is concerned that someone from a competing company could stand outside the b
hoa [83]

Answer:

Option A i.e., AES is correct.

Explanation:

The user corporation is installing the wireless server and seems to be worried when anyone representing the rival corporation might stands outside that property as well as gather wireless information. He ensured that corporation which WPA2 is safe. However, AES creates WPA2 stronger than WPA.

  • Option B is incorrect according to the following scenario because it is the security mechanism used when component through the IEEE 802.11i WLAN standard.
  • Option C is incorrect according to the following scenario because it is the protocol initially developed for configure wireless clients to such a dial-in connection device.
  • Option D is also incorrect according to the following scenario because it is the terminal access control.
6 0
4 years ago
Other questions:
  • If you want a user to enter exactly 20 values which loop would be the best to use
    12·1 answer
  • Electronic files created on a computer using programs such as word software are considered to be
    15·1 answer
  • A _____ is a digital media file distributed over the Internet using syndication feeds for playback on mobile devices and persona
    6·1 answer
  • In a cellular network, where does each wireless base station connect to?
    9·1 answer
  • In the receiving computer, UDP receives a datagram from the __________ layer.
    15·1 answer
  • What is the output of the following program segment? int main() { int num = 5; cout &lt;&lt; num &lt;&lt;" "; change(num); cout
    8·1 answer
  • 1. What is Computer Hardware?
    14·1 answer
  • Why is it important to try to make financial decisions without emotions.
    12·2 answers
  • Which is the most accurate description of which cell contains a nucleus
    5·1 answer
  • Cómo surge y cuál es el objetivo del observatorio de radio y televisión
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!