-
카테고리
-
세부 분야
프로그래밍 언어
-
해결 여부
해결됨
16분쯤 bonusPoint += price * bonusRatio 관련 질문
21.12.16 10:51 작성 조회수 165
0
안녕하세요
intellij 사용 중입니다
Customer class의
calcPrice method 질문인데요
bonusPoint += price * bonusRatio
이부분입니다
bonusPoint += price * bonusRatio 와
bonusPoint = bonusPoint + price * bonusRatio
는 같은 거 아닌가요?
bonusPoint = bonusPoint + price * bonusRatio
이렇게 쓰면 type error가 나옵니다
bonusPoint += price * bonusRatio
이렇게 쓰면 안 나오고요
+= 는 형변환 까지 해주나요?
감사합니다
답변을 작성해보세요.
1
김슬기
2021.12.18
네 맞아요.
복합대입연산자는
bonusPoint = (int) (bonusPiont + price * bonusRatio)
형태와 같이 좌변의 변수 자료형에 맞게 형변환이 자동으로 일어납니다.
형변환을 위한 (int)부분이 보이지 않을뿐입니다.
답변 1