Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
test-spring
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
倪 泽文
test-spring
Commits
c985759f
Commit
c985759f
authored
1 year ago
by
倪 泽文
Browse files
Options
Downloads
Patches
Plain Diff
删除comment19.md
parent
bd8f35fb
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
comment19.md
+0
-24
0 additions, 24 deletions
comment19.md
with
0 additions
and
24 deletions
comment19.md
deleted
100644 → 0
+
0
−
24
View file @
bd8f35fb
```
待评审函数开始@GetMapping("/")
String home() {
List demo = new ArrayList()<Integer>;
demo.add(1);
for (Integer i:demo) {
System.out.println(demo);
return "last is compele lats use a simple one!";
}
return "last is compele lats use a simple one!";
}```待评审函数结束这个函数有一个逻辑错误。在for循环中,`System.out.println(demo);`语句每次都会打印`demo`的当前值,而不是整个列表。因此,每次循环结束后,`demo`的值都会被更新,最终的返回值也会随着循环次数的增加而增加。这并不是你想要的结果。
如果你想返回列表中的最后一个元素,你应该在for循环结束后再返回它。修改后的代码如下:
```
java
@GetMapping("/")
String home() {
List
<Integer>
demo = new ArrayList
<>
();
demo.add(1);
for (Integer i : demo) {
System.out.println(i);
}
return demo.get(demo.size() - 1);
}
```
这样,函数就会返回列表中的最后一个元素。
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment