Last active
March 23, 2021 14:33
-
-
Save GIBZ-GIPE/a0fb235a082ff02d781aaa8cd419a875 to your computer and use it in GitHub Desktop.
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
class Calculator { | |
double _lastResult = 0; | |
double subtract(double a, [double b]) { | |
if (b != null) { | |
_lastResult = a - b; | |
} else { | |
_lastResult -= a; | |
} | |
return _lastResult; | |
} | |
} | |
void main() { | |
var calc = Calculator(); | |
print(calc.subtract(5, 2)); // 5 - 2 = 3 | |
print(calc.subtract(1)); // 3 - 1 = 2 | |
print(calc.subtract(10, 9)); // 10 - 9 = 1 | |
print(calc.subtract(1)); // 1 - 1 = 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment