The method checkOperator receives three string values — operator, i, j — from the main method. Complete the checkOperator method so that the two integer values are added. The result of the operation is returned to the main method. The operator argument should determine whether to add or subtract.
Computer scienceProgramming languagesJavaCode organizationObject-oriented programmingClasses and objectsObjects
Convert text input
Using logic to add two integers
Report a typo
Sample Input 1:
true
5
2Sample Output 1:
7Write a program in Java 17
import java.util.Scanner;
class IfTrueAdd {
public static int checkOperator(String b, String si, String sj) {
// Write your code here
// ...
// Do not change this code
if (operator) {
return i + j;
} else {
return i - j;
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String operator = scanner.next();
String i = scanner.next();
String j = scanner.next();
System.out.printf("%d", checkOperator(operator, i, j));
}
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.