Skip to content

Refactor greeting logic in HelloApp#6

Open
HarryDebugs wants to merge 1 commit intomainfrom
feature/UC6-substring-method
Open

Refactor greeting logic in HelloApp#6
HarryDebugs wants to merge 1 commit intomainfrom
feature/UC6-substring-method

Conversation

@HarryDebugs
Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings March 28, 2026 04:18
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors HelloApp greeting output to support greeting multiple provided names instead of only the first CLI argument.

Changes:

  • Inverts the argument check to handle the no-args case first (Hello, World!).
  • Builds a comma-separated list of all CLI args and prints them in the greeting.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +7 to +11

for (String name : args) {
nameBuilder.append(name).append(", ");
}

Copy link

Copilot AI Mar 28, 2026

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 the blank lines in this block (e.g., the empty lines after new StringBuilder(); and after the loop). Please remove trailing spaces to avoid unnecessary diffs and potential style/lint failures.

Suggested change
for (String name : args) {
nameBuilder.append(name).append(", ");
}
for (String name : args) {
nameBuilder.append(name).append(", ");
}

Copilot uses AI. Check for mistakes.
Comment on lines +6 to +15
StringBuilder nameBuilder = new StringBuilder();

for (String name : args) {
nameBuilder.append(name).append(", ");
}

if (nameBuilder.length() > 0) {
String names = nameBuilder.substring(0, nameBuilder.length() - 2);
System.out.println("Hello, " + names + "!");
}
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the else branch, if (nameBuilder.length() > 0) is redundant because this code path already implies args.length > 0. Also building with a trailing ", " then trimming via substring is harder to read and does extra work; consider String.join(", ", args) or StringJoiner to avoid the trim step.

Suggested change
StringBuilder nameBuilder = new StringBuilder();
for (String name : args) {
nameBuilder.append(name).append(", ");
}
if (nameBuilder.length() > 0) {
String names = nameBuilder.substring(0, nameBuilder.length() - 2);
System.out.println("Hello, " + names + "!");
}
String names = String.join(", ", args);
System.out.println("Hello, " + names + "!");

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants