CarleySamuel
14.06.2021 •
Computers and Technology
Create a function void process(char ch, int x, int y)- to accept an arithmetic operator (+,-./, in argum
ch and two integers in arguments x and y. Now on the basis of the operator stored in ch perform the operator
in x and y and print the final result. Also, write a main function to input the two integers and an arithmetit
operator, and by invoking function process() print the output.
Example: Input:
First Integer
Second Integer
: 6
Value of ch
Output: The result of 5 and 7 on * = 24
write in java
Solved
Show answers
More tips
- C Computers and Internet Are there special gaming mice?...
- L Leisure and Entertainment When will Maslenitsa start?...
- F Food and Cooking Discovering the Mysterious Fruit of Feijoa...
- B Business and Finance How to Open an Online Store? A Detailed Guide for Beginners...
- W Work and Career How to Write a Resume That Catches the Employer s Attention?...
- C Computers and Internet Е-head: How it Simplifies Life for Users?...
- F Family and Home How to Choose the Best Diapers for Your Baby?...
- F Family and Home Parquet or laminate, which is better?...
- L Leisure and Entertainment How to Properly Wind Fishing Line onto a Reel?...
- L Leisure and Entertainment How to Make a Paper Boat in Simple Steps...
Answers on questions: Computers and Technology
- C Computers and Technology Create a security management policy that addresses the management and the separation of duties throughout the seven domains of a typical IT infrastructure. You are to define...
- C Computers and Technology For this assignment, create a flowchart using Flowgorithm for Programming Exercise 5 on page 121 of the textbook. Your main function (Flowgorithm calls modules functions) will...
- H History Who s your fav harry potter character and why?:)...
- M Mathematics A building is 50 feet hight. At a distance away from the building, an observer notices that the angle of ele degrees. To the nearest foot, how far the observer from the base...
- M Mathematics On a map, two cities measure 5.2 inches apart. The scale of the map is 2in.16miles. What is the actual distance between the cities?...
- M Mathematics pedro wants to buy a video game, so he makes a budget his income is 6$ a week for doing chores at home. If he spends 1$ a week, he will save 5$ a week. The video game costs...
- M Mathematics The average adult male s body is made up of about 60% water. A man weighs 160 pounds. How many fluid Ounces of his weight is water? • 16 dry ounces = 1 pound • 1.04 dry ounces...
- E English In paragraph 30 how were the Jews restricted in Amsterdam according to Anne’s diary entry? Please if you can figure this out thank you...
- E English What is the main theme of the excerpt “Save a Kingdom”...
- B Biology Identify details in the text that support sustainable development goals....
Ответ:
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
if(ch == '+'){
System.out.print(x+y); }
If the character is -, this prints the difference of both integers
else if(ch == '-'){
System.out.print(x-y); }
If the character is *, this prints the product of both integers
else if(ch == '*'){
System.out.print(x*y); }
If the character is /, this prints the division of both integers.
else if(ch == '/'){
if(y!=0){
double num = x;
System.out.print(num/y); }
else{
This is executed if the denominator is 0
System.out.print("Cannot divide by 0"); }}
Invalid operator is printed for every other character
else{
System.out.print("Invalid operator");}
}
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
System.out.print("Enter two integers: ");
x = input.nextInt(); y = input.nextInt();
Get input for the operator
System.out.print("Enter operator: ");
ch = input.next().charAt(0);
Call the function
process(ch,x, y);
}
}
Ответ:
These acts all helped the countries form new states. These acts all helped to move frontiers further westward.
Explanation: