Skip to content
Snippets Groups Projects
Commit 4cca776a authored by Stian Andersen Negård's avatar Stian Andersen Negård
Browse files

Fix of expansion v

parent 9302e6f6
No related branches found
No related tags found
No related merge requests found
Pipeline #72190 passed
...@@ -52,11 +52,11 @@ public class CalculatorResource { ...@@ -52,11 +52,11 @@ public class CalculatorResource {
*/ */
public int sum(String expression){ public int sum(String expression){
String[] split = expression.split("[+]"); String[] split = expression.split("[+]");
int length = len(split) int length = len(split);
for(int i = 0; i<length; i++){ for(int i = 0; i<length; i++){
int number = Integer.parseInt(split[i]); int number = Integer.parseInt(split[i]);
int sum += number int sum += number;
} }
return sum; return sum;
} }
...@@ -68,33 +68,33 @@ public class CalculatorResource { ...@@ -68,33 +68,33 @@ public class CalculatorResource {
*/ */
public int subtraction(String expression){ public int subtraction(String expression){
String[] split = expression.split("[-]"); String[] split = expression.split("[-]");
int length = len(split) int length = len(split);
for(int i = 0; i<length; i++){ for(int i = 0; i<length; i++){
int number = Integer.parseInt(split[i]); int number = Integer.parseInt(split[i]);
int result -= number int result -= number;
} }
return result; return result;
} }
public int multiplication(String expression){ public int multiplication(String expression){
String[] split = expression.split("[*]"); String[] split = expression.split("[*]");
int length = len(split) int length = len(split);
for(int i = 0; i<length; i++){ for(int i = 0; i<length; i++){
int number = Integer.parseInt(split[i]); int number = Integer.parseInt(split[i]);
int result *= number int result *= number;
} }
return result; return result;
} }
public int division(String expression){ public int division(String expression){
String[] split = expression.split("[/]"); String[] split = expression.split("[/]");
int length = len(split) int length = len(split);
for(int i = 0; i<length; i++){ for(int i = 0; i<length; i++){
int number = Integer.parseInt(split[i]); int number = Integer.parseInt(split[i]);
int result /= number int result /= number;
} }
return result; return result;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment