Last active
December 19, 2017 11:33
-
-
Save livelikeabel/e0d671b6616f644ceeb98efea09432dd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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