-
Notifications
You must be signed in to change notification settings - Fork 0
Update HelloApp.java #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,9 +1,20 @@ | ||||||||||||||||||||||||||||||||||
| public class HelloApp { | ||||||||||||||||||||||||||||||||||
| public static void main(String[] args) { | ||||||||||||||||||||||||||||||||||
| if (args.length > 0) { | ||||||||||||||||||||||||||||||||||
| System.out.println("Hello, " + args[0] + "!"); | ||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||
| if (args.length == 0) { | ||||||||||||||||||||||||||||||||||
| System.out.println("Hello, World!"); | ||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||
| StringBuilder nameBuilder = new StringBuilder(); | ||||||||||||||||||||||||||||||||||
| boolean first = true; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| for (String name : args) { | ||||||||||||||||||||||||||||||||||
| if (!first) { | ||||||||||||||||||||||||||||||||||
| nameBuilder.append(", "); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| nameBuilder.append(name); | ||||||||||||||||||||||||||||||||||
| first = false; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
| System.out.println("Hello, " + nameBuilder.toString() + "!"); | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+6
to
+17
|
||||||||||||||||||||||||||||||||||
| StringBuilder nameBuilder = new StringBuilder(); | |
| boolean first = true; | |
| for (String name : args) { | |
| if (!first) { | |
| nameBuilder.append(", "); | |
| } | |
| nameBuilder.append(name); | |
| first = false; | |
| } | |
| System.out.println("Hello, " + nameBuilder.toString() + "!"); | |
| String joinedNames = String.join(", ", args); | |
| System.out.println("Hello, " + joinedNames + "!"); |
Copilot
AI
Mar 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nameBuilder.toString() is redundant here because string concatenation will call toString() implicitly. Using nameBuilder directly avoids the extra call and is a bit clearer.
| System.out.println("Hello, " + nameBuilder.toString() + "!"); | |
| System.out.println("Hello, " + nameBuilder + "!"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There appears to be trailing whitespace on this blank line; please remove it to keep diffs clean and avoid lint/formatting noise.