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
How does ur computer know that its cursor moved
Anton [14]
The sensor of a mouse connected to the computer or the touch pad being touched and swiped around on
8 0
3 years ago
Read 2 more answers
Phil wants to add a new video card, and he is sure the power supply is sufficient to run the new video card. But when he tries t
pshichka [43]

Answer:

Using a SATA to a 6 pin PCI-E adapter.

Explanation:

sometimes you may feel the need to make some upgrades to your computer, video cards are options where an upgrade is made, a 6 Pin PCI-E adapter is 6 pins 12V power adapter used to power a video card where their slots cannot provide them with enough power they require. in a situation where the card requires a lot of power than the slot can provide, 6 pins PCI-E adapter is a very good option.

4 0
3 years ago
Which of these is NOT a benefit of being connected 24/7?
Serjik [45]

Answer:

c

Explanation:

answering messages is a more of a choice than a benifit.

3 0
3 years ago
An attack in which the attacker attempts to impersonate the user by using his or her session token is known as:
svetoff [14.1K]

Answer:

Session hijacking

Explanation:

Session hijacking : Session hijacking is an attack where a user session is taken over by an attacker. A session starts when you log into a service, for example your banking application, and ends when you log out.

5 0
2 years ago
Hi, I need help on a Circle Class Assignment that is due today. If anyone could please help me, I would greatly appreciate it. I
nikklg [1K]

Answer:

hmmm lets see

Explanation:

7 0
3 years ago
Other questions:
  • Search the internet for news of a motor vehicle collision in your community involving drugs or alcohol. Keeping in mind that you
    8·1 answer
  • What's the difference between intranet and extranet ​
    9·1 answer
  • When an item in a menu is black, it means that _____.
    6·2 answers
  • How do you answer questions
    15·1 answer
  • Rain forests clean the air by producing oxygen. Some rain forest plants have healing properties, and can be used as medicine. Ra
    12·1 answer
  • What are some ways to find out what skills you need to develop at work? Check all of the boxes that apply.
    15·2 answers
  • Endnotes are indicated by
    6·2 answers
  • As we move up a energy pyrimad the amount of a energy avaliable to each level of consumers
    10·1 answer
  • Implemente a função ao lado, que recebe um preço e um booleano indicando se já está com desconto ou não. Se o preço for maior qu
    8·1 answer
  • What OC level is primarily used as a regional isp backbone, and occasionally by very large hospitals, universities, or other maj
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!