Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using Java Write a program called Arithmetic that takes three command-line argum

ID: 3700936 • Letter: U

Question

Using Java
Write a program called Arithmetic that takes three command-line arguments: two integers followed by an arithmetic operator (+, -, * or /). The program shall perform the corresponding operation on the two integers and print the result.
Using Java
Write a program called Arithmetic that takes three command-line arguments: two integers followed by an arithmetic operator (+, -, * or /). The program shall perform the corresponding operation on the two integers and print the result.

Write a program called Arithmetic that takes three command-line arguments: two integers followed by an arithmetic operator (+, -, * or /). The program shall perform the corresponding operation on the two integers and print the result.

Explanation / Answer

public class Arithmatic {

public static void main(String[] args) {

int num1 = Integer.parseInt(args[0]);

int num2 = Integer.parseInt(args[1]);

String operator = args[2];

if(operator.equalsIgnoreCase("+")) {

int addition = num1+num2;

System.out.println("Addition is : "+ addition);

}

else if(operator.equalsIgnoreCase("-")) {

int subtraction = num1-num2;

System.out.println("Subtraction is : "+ subtraction);

}

else if(operator.equalsIgnoreCase("'*'")) {

int multiplication = num1*num2;

System.out.println("Multiplication is : "+ multiplication);

}

else if(operator.equalsIgnoreCase("/")) {

int division = num1/num2;

System.out.println("Division is : "+ division);

}

}

}

We used '*' for multiplication. jvm interprets * as "all files and folders in the current directory"

thats why we user '*'

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote