Skip to content

Instantly share code, notes, and snippets.

@livelikeabel
Last active December 19, 2017 11:33
Show Gist options
  • Select an option

  • Save livelikeabel/e0d671b6616f644ceeb98efea09432dd to your computer and use it in GitHub Desktop.

Select an option

Save livelikeabel/e0d671b6616f644ceeb98efea09432dd to your computer and use it in GitHub Desktop.
package stringCalculator;
import java.util.Scanner;
public class StringCalculatorIf {
public static String[] myInput() {
Scanner sc = new Scanner(System.in);
String[] splitedValue = sc.nextLine().split(" ");
sc.close();
return splitedValue;
}
public static int calculate(String[] value) {
int first = Integer.parseInt(value[0]);
int second = Integer.parseInt(value[2]);
String operator = value[1];
if (operator == "+") {
int ret = first+second;
return ret;
}
if (operator == "-") {
return first - second;
}
if (operator == "*") {
return first * second;
}
if (operator == "/") {
return first / second;
}
System.out.println(first);
System.out.println(operator);
System.out.println(second);
return 404;
}
public static void main(String[] args) {
String[] arr = myInput();
// System.out.println(arr[0]);
// System.out.println(arr[1]);
// System.out.println(arr[2]);
System.out.println(calculate(arr));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment