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

MOre fixes to calc

parent 4cca776a
No related branches found
No related tags found
No related merge requests found
Pipeline #72192 passed
......@@ -53,10 +53,11 @@ public class CalculatorResource {
public int sum(String expression){
String[] split = expression.split("[+]");
int length = len(split);
int sum = 0;
for(int i = 0; i<length; i++){
int number = Integer.parseInt(split[i]);
int sum += number;
sum += number;
}
return sum;
}
......@@ -69,10 +70,11 @@ public class CalculatorResource {
public int subtraction(String expression){
String[] split = expression.split("[-]");
int length = len(split);
int result = 0;
for(int i = 0; i<length; i++){
int number = Integer.parseInt(split[i]);
int result -= number;
result -= number;
}
return result;
}
......@@ -80,10 +82,11 @@ public class CalculatorResource {
public int multiplication(String expression){
String[] split = expression.split("[*]");
int length = len(split);
int result = 0;
for(int i = 0; i<length; i++){
int number = Integer.parseInt(split[i]);
int result *= number;
result *= number;
}
return result;
}
......@@ -91,10 +94,11 @@ public class CalculatorResource {
public int division(String expression){
String[] split = expression.split("[/]");
int length = len(split);
int result = 0;
for(int i = 0; i<length; i++){
int number = Integer.parseInt(split[i]);
int result /= number;
result /= number;
}
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