aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJake Wharton <jakewharton@gmail.com>2018-04-23 14:22:09 -0400
committerGitHub <noreply@github.com>2018-04-23 14:22:09 -0400
commit9ea843d73170f75d735114cdca6ba2463965cafb (patch)
tree183003ca1ee2a049593dd9b02742ff1534425334
parent8e9b2ec3c3e9d09e19c88ef3d1fc92ab2f6472e2 (diff)
downloadjavapoet-9ea843d73170f75d735114cdca6ba2463965cafb.tar.gz
Initialize multiplication result to 1.
Otherwise the result is always 0.
-rw-r--r--README.md4
1 files changed, 2 insertions, 2 deletions
diff --git a/README.md b/README.md
index d415a88..32d65fa 100644
--- a/README.md
+++ b/README.md
@@ -104,7 +104,7 @@ we want to make the operation and range configurable. Here's a method that gener
private MethodSpec computeRange(String name, int from, int to, String op) {
return MethodSpec.methodBuilder(name)
.returns(int.class)
- .addStatement("int result = 0")
+ .addStatement("int result = 1")
.beginControlFlow("for (int i = " + from + "; i < " + to + "; i++)")
.addStatement("result = result " + op + " i")
.endControlFlow()
@@ -117,7 +117,7 @@ And here's what we get when we call `computeRange("multiply10to20", 10, 20, "*")
```java
int multiply10to20() {
- int result = 0;
+ int result = 1;
for (int i = 10; i < 20; i++) {
result = result * i;
}