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
Select the correct answer. Which keyboard feature is a form feed character? A. uppercase letters B. Control key C. lowercase let
Valentin [98]

Answer:

B . control key

Explanation:

dadadadads

4 0
3 years ago
The following is the correct way to write a for loop
Rzqust [24]

Answer:

for i in range

Explanation:

This is the only excerpt of code

3 0
3 years ago
➪ How many types of Engineering are there in the world ?<br>⛄​​
aleksley [76]

There are mainly five types of engineers found in the world. Each of them has a different set of skills and knowledge concerning their relative field.

<h3>Who is called an Engineer?</h3>

An Engineer may be defined as an individual who formats, designs, modifies, and creates machinery or technical equipment like software programs, construction buildings, bridges, etc.

The five types of Engineers are as follows:

  • Civil Engineers.
  • Chemical Engineers.
  • Electrical Engineers.
  • Mechanical Engineers.
  • Computer Engineers.

Civil engineers deal with the construction of buildings, bridges dams, airports, etc. Chemical engineers are associated with developing the products such as medicines, petrochemicals, plastics, etc.

Electrical engineers design and develop the manufacturing of electrical equipment like navigation systems, radar, communication systems, electric motors, etc.

Mechanical engineers always maintain their focus on manufacturing power-producing and power-using machines like electric generators, gas turbines, refrigerators, air-conditioners, etc.

Computer engineers deal with designing, manufacturing, and examining all software operated within an institution's computer system.

All such types of engineers work in their respective fields for designing, and manufacturing products and their delivery which makes the life of an individual easy, efficient, and reliable.

Therefore, it is well described above.

To learn more about Engineers, refer to the link:

brainly.com/question/17169621

#SPJ1

5 0
2 years ago
Read 2 more answers
Functions<br> of beaker​
pishuonlain [190]

Answer:

Beaker Purpose

Although the purpose of a beaker is to contain and measure liquids, the glassware can come in a multitude of shapes and sizes. Most often, a beaker is cylindrical in shape and has a flat bottom. Some beakers have a small beak or spout to aid in the pouring of liquids.

Here hope that helps know mark me as brill

3 0
3 years ago
Write a program that gets a list of integers from input, and outputs the integers in ascending order (lowest to highest). The fi
kozerog [31]

Answer:

see explaination

Explanation:

#include <iostream>

#include <vector>

using namespace std;

void vector_sort(vector<int> &vec) {

int i, j, temp;

for (i = 0; i < vec.size(); ++i) {

for (j = 0; j < vec.size() - 1; ++j) {

if (vec[j] > vec[j + 1]) {

temp = vec[j];

vec[j] = vec[j + 1];

vec[j + 1] = temp;

}

}

}

}

int main() {

int size, n;

vector<int> v;

cin >> size;

for (int i = 0; i < size; ++i) {

cin >> n;

v.push_back(n);

}

vector_sort(v);

for (int i = 0; i < size; ++i) {

cout << v[i] << " ";

}

cout << endl;

return 0;

}

7 0
3 years ago
Other questions:
  • Your health insurance company gives you a discount if you wear a fitness-tracking bracelet. After wearing it for a few months, y
    5·1 answer
  • What information is kept in the cached lookups folder for a dns server?
    9·1 answer
  • A common type of non-volatile memory is _____.
    12·1 answer
  • What is the difference between keywords and identifiers in c++ ?
    5·1 answer
  • You've been hired by Maple Marvels to write a C++ console application that displays information about the number of leaves that
    5·1 answer
  • Question 7 (1 point)<br> Increasing hue levels means increasing saturation.<br> True<br> False
    11·1 answer
  • How Do you get Splatoon two for free
    6·2 answers
  • What are the responsibilities of the DBA and the database designers?
    7·1 answer
  • Create a new Java class called AverageWeight. Create two arrays: an array to hold 3 different names and an array to hold their w
    13·1 answer
  • Accept total number of participants (B) in class. A group of
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!