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
"You are on a service call to fix a customer’s printer when she asks you to install a software package. The software is on a per
pickupchik [31]

Answer:

Ask her to get a genuine software

Explanation:

if i will install, it can cause the following problems:

1. Prated software makes your system Vulnerable to the security attacks because the activities of the software are not monitored by any organization and no one is responsible for anything bad happened to your system.

2. It may stop working anytime because there would not be maintenance patches available for it so that it can work properly.

3. It cannot be updated and may cause problems in core functionalities of it.

4.Serious legal actions can be taken against anyone using them because  economy has drastic decrease due ti use of it.

7 0
3 years ago
Where should you look for most objective and unbaised information
jekas [21]
Google, would be the best because of all of the different site, hope this helps!
: )
8 0
2 years ago
Create an interactive program to use class a LightsOut class to allow a user to play a game. Each step in the game will require
expeople1 [14]

Answer:

9+10=21

Explanation:

wyd boy

8 0
3 years ago
Which two editions of Windows 7 support 64 bit CPUs? Choose two out of Professional, Business, Starter, or Home Premium.
Tju [1.3M]
Home premium, professional
6 0
3 years ago
To achieve balance—that is, to operate an information system that satisfies the user and the security professional—the security
marta [7]

the answer is True

there has to be a balance between security and the user experience

7 0
3 years ago
Other questions:
  • In order to paint a wall that has a number of windows, we want to know its area. Each window has a size of 2 ft by 3 ft. Write a
    12·2 answers
  • Mobile devices typically come pre installed with standard apps like web browsers , media players, and mapping programs true or f
    9·1 answer
  • Hard drives are usually self-contained, sealed devices. Why must the case for the hard drive remain sealed closed?
    8·1 answer
  • • Describe the steps in detail that the operating system performs to handle interrupts, including ISRs, the stack, and hardware?
    5·1 answer
  • The manager of a sports club has data about the club members' ages in a workbook. He wants to find which age is most common. Whi
    13·2 answers
  • Print either "Fruit", "Drink", or "Unknown" (followed by a newline) depending on the value of userItem. Print "Unknown" (followe
    13·1 answer
  • Words that have a special meaning in a programming language are called
    13·1 answer
  • A 'array palindrome' is an array which, when its elements are reversed, remains the same (i.e., the elements of the array are sa
    6·1 answer
  • Using the Vigenere cipher, does the length of the key matter?
    8·1 answer
  • Factoring of integers. Write a python program that asks the user for an integer and then prints out all its factors. For example
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!