Skip to content

[문자열 계산기] 김하빈 미션 제출합니다.#6

Open
KIM-GOING wants to merge 5 commits intoJava-JavaScript-Language-Stuty:mainfrom
KIM-GOING:kim-going
Open

[문자열 계산기] 김하빈 미션 제출합니다.#6
KIM-GOING wants to merge 5 commits intoJava-JavaScript-Language-Stuty:mainfrom
KIM-GOING:kim-going

Conversation

@KIM-GOING
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown
Contributor

@moongua404 moongua404 left a comment

Choose a reason for hiding this comment

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

코드가 되게 간결하고 분명해서 읽기 쉬운 코드였던 것 같습니다! C++의 느낌이 많이 나지만...ㅋㅋㅋㅋ 이렇게 술술 읽히는 코드도 오랫만에 보는 것 같아요ㅎㅎ
1주차 미션 너무 수고많으셨습니다!

public class Application {
public static void main(String[] args) {
// TODO: 프로그램 구현
Scanner sc = new Scanner(System.in);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

다음에는 미션에서 적혀있는대로 camp.nextstep.edu.missionutils에서 제공하는 Console을 사용해서 입력을 구현해주세요!

}
System.out.println(sum);
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

주석 다셨던 단위로 함수를 분리하면 코드의 흐름이 한눈에 들어올 것 같아요!

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

동의합니다

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

동의합니다


// 숫자의 합 출력
int sum = 0;
for(int i = 0; i < number.size(); i++) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

stream API와 Reduce를 써도 좋을 것 같아요! for문을 쓰더라도 for (int value : number)이었나 여튼 원소를 순회하는게 가독성이나 효율성 측면에서 더 좋을 것 같아요!

// 예외 처리를 위한 예비출력
System.out.println("예외");
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Character 단위로 하면 1의자리를 제외한 숫자는 표현이 안되지 않을까요...? ex) 입력 : 32 -> 결과 : 5

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

동의합니다

// 예외 처리를 위한 예비출력
System.out.println("예외");
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

이렇게 순회하면서 number 이라는 백터에 담을 수도 있지만 split을 통해 쪼개는 것이 더 간단할 것 같아요!
만약에 그냥 숫자인 문자만 얻기 위함이라면 Stream과 filter을 통해 보다 쉽게 결과를 얻을 수 있을 것 같아요!

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

동의합니다.

words = sc.next();

// 커스텀 구분자 확인
if(words.charAt(0)=='/' && words.charAt(1)=='/' && words.charAt(3)=='\\' && words.charAt(4)=='n') {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

여기도 정규표현식 쓰면 간결해질 것 같아요!

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

words의 index 2부분에만 구분자를 받을 경우, 스터디장님이 입력한 예외케이스를 보면 구분자를 여러문자로 입력했을 때 예외 처리 문제가 있을 것 같습니당

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

맞네요 생각 못했어요

public static void main(String[] args) {
// TODO: 프로그램 구현
Scanner sc = new Scanner(System.in);
Vector<Integer> number = new Vector<>();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

백터를 쓰신 이유가 있을까요? 이유가 없다면 Vector 외에도 다른 선택지가 많을 것 같아요!
참고 글

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Vector말고 ArrayList로 불필요한 동기화를 줄여서 성능도 향상시켜보면 어떨까용?
Vector vs ArrayList참고자료
Vector을 자바에서 쓰지않는 이유

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

저도 덕분에 자바의 여러 중요한 부분들을 공부하게된 것 같아 좋네요 :)

@daeGULLL
Copy link
Copy Markdown

daeGULLL commented Feb 8, 2025

스터디장님 말대로 c++느낌이 강하게 나는 잼나는 코드였습니다!! 저도 감자라 뭔가 말하기 무안하네요ㅋㅋㅋㅋ 자바에 좀더 익숙해지시면 자바틱하게 바꿔나가시면 깔끔한 코드라는 장점을 더 강화시키실 수 있을거라 생각합니다 수고하셨습니다~~

Copy link
Copy Markdown

@seulnan seulnan left a comment

Choose a reason for hiding this comment

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

너무 고생많으셨습니다:)

저도 리뷰하면서 많은걸 공부하게 된 것 같아 너무 좋았습니다!
다만, 예외처리 부분에서 하드코딩된 부분이 있는 것 같아서 예외로직도 분리해보고, 테스트코드도 작성해보셨으면 더 좋은 코드가 될듯해용 😃

// 숫자와 문자 분리
for(int i=5; i<words.length(); i++) {
char word = words.charAt(i);
if(word >= 48 && word <= 57) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

아마 숫자인지를 확인하기위해 ASCII값을 직접 비교하는 로직을 넣으신 거겠죠..?
Java에서는 Character.isDigit()같은 유용한 API를 활용하면 가독성도 좋아지고 로직도 간단해질 것 같아용!

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

동의합니다!

public static void main(String[] args) {
// TODO: 프로그램 구현
Scanner sc = new Scanner(System.in);
Vector<Integer> number = new Vector<>();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Vector말고 ArrayList로 불필요한 동기화를 줄여서 성능도 향상시켜보면 어떨까용?
Vector vs ArrayList참고자료
Vector을 자바에서 쓰지않는 이유

public static void main(String[] args) {
// TODO: 프로그램 구현
Scanner sc = new Scanner(System.in);
Vector<Integer> number = new Vector<>();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

저도 덕분에 자바의 여러 중요한 부분들을 공부하게된 것 같아 좋네요 :)


// 문자열 입력
System.out.println("덧셈할 문자열을 입력해 주세요.");
words = sc.next();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nextLine()대신 공백기준으로 한단어만 입력받는 next()를 사용하신 이유가 있을까용?

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.

5 participants