CodeGym /Java Course /์ž๋ฐ” ๊ตฌ๋ฌธ /์‹ค์ œ ์œ ํ˜•

์‹ค์ œ ์œ ํ˜•

์ž๋ฐ” ๊ตฌ๋ฌธ
๋ ˆ๋ฒจ 10 , ๋ ˆ์Šจ 7
์‚ฌ์šฉ ๊ฐ€๋Šฅ

"์‹ค์ œ(์†Œ์ˆ˜) ์œ ํ˜•์— ๋Œ€ํ•œ ๋ช‡ ๊ฐ€์ง€ ํฅ๋ฏธ๋กœ์šด ์‚ฌํ•ญ์ด ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ์˜ˆ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค."

float f = 3 / 5;

"์ด ๊ณ„์‚ฐ ๊ฒฐ๊ณผ f๋Š”โ€ฆ 0์ด ๋ฉ๋‹ˆ๋‹ค!"

"๊ทธ๋ž˜, ๋ฆฌ์‹œ๊ฐ€ ๋‚˜ํ•œํ…Œ ๊ทธ๋Ÿฐ ๋ง์„ ํ–ˆ์–ด."

"์•„, ๊ทธ๋žฌ์–ด? ์ข‹์•„. ๋ฐ˜๋ณต์€ ์ •๋ง ๋„์›€์ด ๋ผ."

"์—ฌ๊ธฐ์—๋Š” ์˜ค๋ฅ˜๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. ๋‚˜๋ˆ—์…ˆ์—๋Š” ๋‘ ๊ฐœ์˜ ์ •์ˆ˜๊ฐ€ ํฌํ•จ๋˜๋ฏ€๋กœ ๋‚˜๋จธ์ง€๋Š” ๋ฌด์‹œ๋ฉ๋‹ˆ๋‹ค. ์ด๋Ÿฐ ์ผ์ด ๋ฐœ์ƒํ•˜์ง€ ์•Š๋„๋ก ๋‚˜๋ˆ„๊ธฐ์˜ ๋‘ ์ˆซ์ž ์ค‘ ์ ์–ด๋„ ํ•˜๋‚˜๋Š” ๋ถ„์ˆ˜์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค."

"์ˆซ์ž ์ค‘ ํ•˜๋‚˜๊ฐ€ ๋ถ„์ˆ˜์ด๋ฉด ๋‘ ๋ฒˆ์งธ ์ˆซ์ž๊ฐ€ ๋จผ์ € ๋ถ„์ˆ˜ ์œ ํ˜•์œผ๋กœ ๋ณ€ํ™˜๋œ ๋‹ค์Œ ๋‚˜๋ˆ—์…ˆ์ด ์ˆ˜ํ–‰๋ฉ๋‹ˆ๋‹ค."

"๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค."

๋ถ„์ˆ˜ ํ‘œ๊ธฐ๋ฒ•:
float f = 3.0f / 5.0f;
float f = 3.0f / 5;
float f = 3 / 5.0f;

"๋‚˜๋ˆ—์…ˆ์— ๋ณ€์ˆ˜๊ฐ€ ํฌํ•จ๋œ๋‹ค๋ฉด?"

"๊ทธ๋Ÿผ ์ด๋ ‡๊ฒŒ ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค."

์ •์ˆ˜ ๋ณ€์ˆ˜๋ฅผ ๋ถ„์ˆ˜ ๊ฐ’์œผ๋กœ ๋ณ€ํ™˜:
int a = 3, b = 5;
float f = (a * 1.0f) / b;

int a = 3, b = 5;
float f = a / (b * 1.0f);

int a = 3, b = 5;
float f = (a * 1.0f) / (b * 1.0f);

 int a = 3, b = 5;
float f = (float) a / b; 

"์–ด์ƒ‰ํ•ด๋ณด์ด๋„ค์š”. ๋˜ ๋‹ค๋ฅธ ๋ถ„๋‹จ ์ž‘์ „, ์ข€ ๋” ํŽธ๋ฆฌํ•œ ๊ฒŒ ์žˆ์ง€ ์•Š์Šต๋‹ˆ๊นŒ?"

"์•„๋‹ˆ. ์ด๊ฒŒ ๋‹ค์•ผ."

"์•Œ์•˜์–ด. ๋ฌธ์ œ ์—†์–ด."

์ฝ”๋ฉ˜ํŠธ
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION