Last active
September 9, 2020 14:26
-
-
Save evjeny/18128ef617462b65567c37563e4aef40 to your computer and use it in GitHub Desktop.
First hw for prog_intro course
This file contains 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
public class Sum { | |
public static void main(String[] args) { | |
int[][] intsArray = new int[args.length][]; | |
for(int i = 0; i < args.length; i++) { | |
intsArray[i] = parseInts(args[i]); | |
} | |
int result = 0; | |
for(int i = 0; i < intsArray.length; i++) { | |
for(int j = 0; j < intsArray[i].length; j++) { | |
result += intsArray[i][j]; | |
} | |
} | |
System.out.println(result); | |
} | |
public static int[] parseInts(final String arg) { | |
final String[] subStrings = arg.trim().split("[ \u2028\u2029\t\n\u000B\f\r\u001C\u001D\u001E\u001F]+"); | |
int[] result = new int[subStrings.length]; | |
for(int i = 0; i < subStrings.length; i++) { | |
if(!subStrings[i].equals("")) { | |
result[i] = Integer.parseInt(subStrings[i]); | |
} | |
} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment