-
Notifications
You must be signed in to change notification settings - Fork 14
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
2주차 Assignment - 정다연 #9
base: main
Are you sure you want to change the base?
Conversation
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.
자바 부분만 다시 한 번 고쳐볼까요? 전반적으로 잘 수행하셨네요!
.mapToDouble(Math::sqrt) | ||
.average() | ||
.orElseThrow(NoSuchElementException::new); | ||
|
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.
잘 작성하셨습니다!!
궁금한 점이기는 한데 혹시 어쩌다 저렇게 들여쓰기가 되었나요..?ㅋㅋㅋ
왜 스트림에서 double을 반환할 때 orElseThrow를 통해 예외 처리를 해야할까요?
사실 averge() 메소드가 반환하는 값은 double 타입이 아니라 Optional 타입입니다.
따라서 orElseThrow가 가지는 의미는 Optional값의 isPresent() 메소드가 true를 반환하지 않을 경우 처리할 예외를 의미합니다! Spring에서 정말로 많이 사용되는 타입이니 기억해 두세요!
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.
저도 왜 저렇게 들여쓰기가 되는지 모르겠습니다ㅜㅜ 일자로 잘 될 거라 생각했는데 자꾸 저렇게 들여쓰기를 해주더라고요 ㅎㅎ... 억지로 고치다가 아직까지는 큰 영향이 없는 것 같아 냅두었습니다... orElseThrow가 꼭 필요한 이유가 궁금했는데 함께 코멘트 남겨주셔서 감사합니다!
double ans1 = action((array -> { | ||
double result = 0; | ||
for (int i = 1; i < array.length; i++) { | ||
if (array[i] > array[i - 1]) { |
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.
앗 이 부분 지금 배열의 인접한 두 원소끼리만 비교를 하고 있어요. 단적으로 현재 배열이 역순으로 정렬되어 있다고 가정해 봅시다.
그러면 if문은 수행이 안되고 result의 값은 반복문이 끝날 때까지 0의 값을 가지고 있겠죠?
다시 한 번 작성해 봅시다...!!
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.
입력된 값을 변경해보지 않고 작성했더니 그런 오류가 발생하네요 ㅎㅎ... 코드 다시 수정하였습니다!
} | ||
br.close(); | ||
} | ||
} |
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.
굳굳 잘 작성하셨습니다!!
SELECT customer.name, products.name, orders.orderdate | ||
FROM orders | ||
JOIN products ON products.productid = orders.productid | ||
JOIN customer ON customer.custid = orders.custid; |
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.
데이터베이스 부분은 깔끔하게 잘 설계하셨네요..!
for (int i = 1; i <= array.length; i++) { | ||
if (array[(int)result] > array[i - 1]) { result = i; } | ||
else { result = i - 1; } | ||
} return array[(int)result]; | ||
})); |
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.
저도 궁금해서 이 코드를 디버깅 해보면서 문제가 무엇인지 찾아보았습니다.
우선 첫 번째로 현재 주어진 배열에서 접근할 수 없는 인덱스의 값(array.length)로 배열에 접근할 가능성이 있다는 1차적인 문제가 있고
무엇보다 if문에서 array[result]의 값이 더 크다는 것이 결정되었으면 result 값이 변경되면 안되는데 완전히 다른 값으로 새롭게 저장되고 있습니다.
따라서 이 코드는 아예 지워버리시고 max라는 변수를 선언하고 0으로 초기화한 다음 배열을 순회하며 max 값보다 큰 값이면 max를 해당 값으로 저장하며 max를 구하시면 됩니다. if (max < array[i]) { max = array[i]; }
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.
확인하여 수정하였습니다!
무조건 array를 사용하려 하다보니 이런 문제가 발생한 것 같습니다... 코멘트를 읽고 수정하며, 입력 값도 변경해보고 if문도 다시 살펴본 결과 말씀해주신 오류를 이해할 수 있었습니다. 이번 문제를 풀며 반복문을 통해 배열에 접근하는 부분을 특히 더 공부해야겠다는 생각이 듭니다... 자세한 코멘트 감사합니다!
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.
고생하셨습니다 과제 통과입니다~~
Description
Important content
Question
Reference