1. Int tipeureul deo jasehi salpyeobogi
Byeonsue jeong-sureul jeojanghago sipdamyeon, Int tipeureul sayonghaeya hamnida. Intneun Integerui jul-imari(go), yeong-eoro “jeong-su”reul tteut-haneun mareseoneun, i tipeuga jeong-sureul jeojanghal su issdaneun geoseul amsihamnida.
Int tipeu byeonsuneun -2 billionbuteo +2 billionkkaji-ui beomwi-eseo jeong-sureul jeojanghal su issseumnida. Deo jeonghwakhi malhamyeon -2,147,483,648buteo 2,147,483,647kkajimnida.
Heungmi로운 sasil
Ireohge eojjeongtteon suchideur-eun keompyuteo memori gujo-wa gwallyeondoeeo issseumnida. Kotlin ( JVM )eseo Int tipeu-ege-neun memori 4 bytega haldangdoebnida. Gak byte memori-neun 8 bitro irueojyeo issseumnida. Gak bit-eun 2 gaji gachi, jeuk 0 ttoneun 1man gajil su issseumnida. Int tipeu byeonsuneun 32 bitreul gajigo, 4,294,967,296 gaji gachi-reul gajil su issseumnida.
I beomwi-ui ban-eun eum-su, nameoji ban-eun yang-su-ege haldangdoeeossseumnida. Geuraeseo gyeolguk -2,147,483,648buteo 2,147,483,647kkaji-ga doeeotseumnida.
2. Int tipeu byeonsu mandeulgi
Int tipeuneun jeong-sureul jeojanghagi wihan tipeuipnida. Kode-eseo jeong-sureul jeojanghal su inneun byeonsureul mandeullyeomyeon, da-eum hyeongtae-ui myeongryeongeul sayonghamyeon doemnida:
var imya: Int
Yeogi-eseo imyaneun byeonsu ireumimnida. Yesi:
| Myeongryeong | Seolmyeong |
|---|---|
|
Jeong-su byeonsu xga saengseongdoebnida |
|
Jeong-su byeonsu countga saengseongdoebnida |
|
Jeong-su byeonsu currentYearga saengseongdoebnida |
Munja-ui keugi(daeso-munja)neun jungyohamnida: var color: Intwa var Color: Intneun dareun du gae-ui byeonsureul seoneonhamnida.
Banhyeon Int Colorwa INT COLOR gateun myeongryeong-eun 컴파일러가 jeonhyeo ihaehaji mothago olyureul ballyeohal geosimnida. Kotlineseoneun meonjeo var/valeul sseugo, geu daeum byeonsu ireum, geu daeum kol론 :eul tonghae tipeureul jeokseumnida. Tipeu ireumeun Intigo, jeongmal geureohge sseumyeo (dae-munja I) rago sseubnida.
3. Byeonsu seoneon-ui jull-im pyohyeon
프로그램-ui han got-eseo gateun tipeu byeonsureul yeoreo gae mandeureoya handamyeon, Javaeseoneun swipyo(,)reul sayonghan jull-im pyohyeoneuro han beon-e seoneonhal su issseumnida.
int x, y, z;
Kotlineseoneun ireon pyohyeon-i eopseumnida: gach byeonsureul gakkak ttaro seoneonhamnida. Wonhamyeon ;(semicolon)eur-eul sayonghae han jul-e yeoreo seoneon-eul sseul su issjiman, botong-eun jul 바kkum-euro sseubnida.
Yesi:
var x: Int; var y: Int; var z: Int
ttoneun
var x: Int;
var y: Int;
var z: Int
4. Gachi haldang
Int tipeu byeonsue gachi-reul neoh-euryeomyeon, da-eum myeongryeongeul sayonghamnida:
imya = gachi
Yeogi-eseo gachi-neun eotteon jeong-su sikdo doel su issseumnida. Yesi:
| Myeongryeong | Bigo |
|---|---|
|
|
|
Byeonsu-e “2 billion” gachi-ga deureogamnida |
|
Byeonsu-e “-10 million” gachi-ga deureogamnida |
|
Compile dooji anhseumnida, iyuneun 3,000,000,000i Int tipeu-ui choedae gachi 2,147,483,647boda keugi ttaemunimnida |
5. Byeonsu chogihwa
Byeonsu saengseong(=seoneon)gwa gachi haldang-eul han myeongryeong-euro hamkke sseul su issseumnida. Botong-eun geureohge sseuneunde, byeonsu-neun daebubun eotteon gachi-reul jeojanghal piryoga saenggineun sungan-e seoneondoegi ttaemunimnida.
Kotlineseoneun da-eum-gwa gatseumnida:
var imya: Int = gachi
Yesi:
| Myeongryeong | Bigo |
|---|---|
|
|
|
Byeonsu-e “2 billion” gachi-ga deureogamnida |
|
Byeonsu-e “-10 million” gachi-ga deureogamnida |
|
Compile dooji anhseumnida, iyuneun 3,000,000,000i Int tipeu-ui choedae gachi: 2,147,483,647boda keugi ttaemunimnida |
6. Jeong-su sik gyesan
Haldang yeonsanja(=deung-ho) oreunjjog-eseoneun eotteon sikdo ol su issseumnida — su, byeonsu, geurigo +, -, *, / gateun yeonsan-ja-ui johabimnida.
Gwalho ( )do sayonghal su issseumnida. Kotlineseo-do suhak-e seo gateun wonsiro, meonjeo gwalho an-ui sik-eul gyesanhan hu, geu bakk-eul gyesanhamnida. Gobhagi wa naenugi-neun dongilhan 우seon-sunwi-reul gajigo, deohagi wa ppaegi보다 우seon-sunwi-ga nopseumnida.
Yesi:
| Myeongryeong | Bigo |
|---|---|
|
Byeonsu-e 8 gachi-ga deureogamnida |
|
Byeonsu-e 1 gachi-ga deureogamnida |
|
Byeonsu-e 6 gachi-ga deureogamnida |
|
I myeongryeong-eul silhaenghamyeon olyuga balsaenghago, peurogeuraemi jonglyodoel geosimnida. |
Sig-e byeonsu-ga chamyeohal sudo issseumnida:
var a: Int = 1 // In byeonsu a, gachi 1i deureogamnida
var b: Int = 2 // In byeonsu b, gachi 2ga deureogamnida
var c: Int = a * b + 2 // In byeonsu c, gachi 4ga deureogamnida
Deo 나아가, gateun byeonsu-ga haldang yeonsanjaui oenjjog-gwa oreunjjog-e dongsi-e naoalk sudo issseumnida:
var x: Int = 5 // In byeonsu x, gachi 5ga deureogamnida
x = x + 1 // In byeonsu x, gachi 6i deureogamnida
x = x + 1 // In byeonsu x, gachi 7i deureogamnida
x = x + 1 // In byeonsu x, gachi 8i deureogamnida
x = x + 1 // In byeonsu x, gachi 9ga deureogamnida
x = x + 1 // In byeonsu x, gachi 10i deureogamnida
I-yuneun Kotlineseo = munjaga “gatta”reul tteuthaneun geosi anira, = oenjjog byeonsu-e oreunjjog sik-eul gyesanhan gyeolgwa gachi-reul neohneun “myeongryeong”igi ttaemunimnida.
7. Jeong-su naenugi
Kotlineseo jeong-sureul jeong-suro naenugimyeon hangsang jeong-suga doemnida. I ttae naenugi nam-eun(=remainder)un beoryeojimnida. Dareun malro hamyeon, so수 jeobun-i beoryeojimnida.
Yesi:
| Myeongryeong | Naenugi gyeolgwa | Bigo |
|---|---|---|
|
2.5 | Byeonsu ae-neun 2ga deureogamnida |
|
6.6667 | Byeonsu be-neun 6i deureogamnida |
|
-1.2 | Byeonsu ce-neun -1i deureogamnida |
|
0.5 | Byeonsu de-neun 0i deureogamnida |
8. Jeong-su naenugi nam-eun (remainder)
Jeong-su-e daehaeseo deohagi, ppaegi, gobhagi, naenugi malgo-do Kotlineseoneun “naenugi nam-eun” yeonsanja-do jej공hamnida. Ireul wihae peoseonteu munja %reul sayonghamnida. Ineun jeong-sureul jeong-su로 naenun “nam-eun”이지, so수 jeobun-i 아닙니다.
Yesi:
| Myeongryeong | Naenugi gyeolgwa | Bigo |
|---|---|---|
|
2, nam-eun 1 | Byeonsu ae-neun 1i deureogamnida |
|
5, nam-eun 0 | Byeonsu be-neun 0i deureogamnida |
|
1, nam-eun 4 | Byeonsu ce-neun 4ga deureogamnida |
|
0, nam-eun 1 | Byeonsu de-neun 1i deureogamnida |
I yeonsanja-neun aju yuyonghago, ja주 sayongdoebnida. yes를 들어, jjag-su인지 아닌지reul algoryeomyeon 2ro 나눈 hue nam-eun-eul 0gwa bigyohamyeon doemnida. Nam-eun-i 0imyeon jjag-su, 1imyeon hol-suimnida.
I geomsa-neun da-eum-gwa gatseumnida:
(a % 2) == 0
Yeogi-eseo, ije an geureohge, a % 2neun 2ro 나눈 nam-eun-eul guhaneun geosimyeo (즉 0 ttoneun 1), ==neun 0gwa bigyohagi wihae sayongdoebnida.
9. Inclement wa decrement
Programming-eseoneun byeonsu gachi-reul 1man큼 nopyeona naechuryeoya hal ttaega aju man습니다. Ireul wihae Kotlineseoneun teukbyeolhan myeongryeong-eul jej공hamnida:
Inclement yeonsanja(1 jeung-ga)는 da-eum-gwa gatseumnida:
a++
I myeongryeong-eun a = a + 1wa gatta — byeonsu aui gachi-reul 1 jeung-gahamnida.
Decrement yeonsanja(1 gam-so)는 da-eum-gwa gatseumnida:
a--
I myeongryeong-eun a = a - 1wa gatta — byeonsu aui gachi-reul 1 gam-sohamnida.
Yesi 1
var x: Int = 5 // In byeonsu x, gachi 5ga deureogamnida
x++ // In byeonsu x, gachi 6i deureogamnida
x++ // In byeonsu x, gachi 7i deureogamnida
x++ // In byeonsu x, gachi 8i deureogamnida
x++ // In byeonsu x, gachi 9ga deureogamnida
x++ // In byeonsu x, gachi 10i deureogamnida
Yesi 2
var x: Int = 5 // In byeonsu x, gachi 5ga deureogamnida
x-- // In byeonsu x, gachi 4ga deureogamnida
x-- // In byeonsu x, gachi 3i deureogamnida
x-- // In byeonsu x, gachi 2ga deureogamnida
x-- // In byeonsu x, gachi 1i deureogamnida
x-- // In byeonsu x, gachi 0i deureogamnida
x-- // In byeonsu x, gachi -1i deureogamnida
GO TO FULL VERSION