Created
January 13, 2020 06:43
-
-
Save dalcon10028/c2734fcc3bd2a9ddbb9375b137f7eeea 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
| import java.util.*; | |
| public class Main { | |
| public static void main(String args[]) { | |
| Scanner sc = new Scanner(System.in); | |
| String exp = sc.next(); | |
| sc.close(); | |
| String []str = exp.split("-"); // '-' 기호 기준으로 배열에 담기 | |
| // 처음 '-'전까지 모두 더하기 | |
| String []tmp = str[0].split("\\+"); | |
| int first=0; | |
| for (String t : tmp) | |
| first += Integer.parseInt(t); | |
| // 처음 '-' 이후 숫자 더하기 | |
| int sum = 0; | |
| for(int i=1; i<str.length; i++){ | |
| String []temp = str[i].split("\\+"); | |
| for (String t : temp) | |
| sum += Integer.parseInt(t); | |
| } | |
| System.out.println(first-sum); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment