Cov txheej txheem:

JAVA - Qhia: 5 Kauj Ruam
JAVA - Qhia: 5 Kauj Ruam

Video: JAVA - Qhia: 5 Kauj Ruam

Video: JAVA - Qhia: 5 Kauj Ruam
Video: QHIA QHOV TSEEB - KUB VAJ LOOG TSUA NEW MUSIC VIDEO 2022 2024, Kaum ib hlis
Anonim
JAVA - Qhia
JAVA - Qhia

Kuv yuav sim coj koj tib neeg los ntawm kev qhia no kom zoo, thiab nrawm. JAVA yog hom lus nyuaj heev nrog rau ntau yam los kawm. Cov kev qhia no tsis xav tias muaj lub luag haujlwm rau kev qhia koj kom raug, tab sis kuv yuav sim ua kom pom tseeb, thiab tso txhua qhov yuam kev tawm. Yog tias koj twb paub lawm nrog JAVA, koj yuav tsum hla ua ntej mus rau ntu tom ntej. Tshooj lus no tsuas yog lus ceeb toom. Tom ntej no peb yuav pib txais tos koj nrog JAVA lus.

Kauj Ruam 1: JAVA - Tau Txais Cov Cuab Yeej

JAVA - Tau Txais Cov Cuab Yeej
JAVA - Tau Txais Cov Cuab Yeej
JAVA - Tau Txais Cov Cuab Yeej
JAVA - Tau Txais Cov Cuab Yeej

Tam sim no, raws li koj tej zaum paub, peb xav tau qee yam cuab yeej los pib sau JAVA code. Koj tuaj yeem tsuas yog siv koj cov ntawv sau, thiab ua nws los ntawm kab hais kom ua, tab sis peb yuav tau txais tus kws tshaj lij, vim nws yooj yim dua thiab nrawm dua. Peb yuav tau txais eclpise JAVA editor. (Yog tias muaj teeb meem tsis txaus ntseeg) KAUJ RUAM #1) Mus rau lub vev xaib ntawm no thiab nyem lub pob ntsuab rub tawm STEP #2) Txuag nws rau koj lub desktop thiab nyem "OK" KAUJ RUAM #3) Thaum nws ua tiav rub tawm, nyem qhov ntawv thiab xaiv " Tshem tawm tag nrho "KAUJ RUAM #4) Koj yuav tsum pom daim nplaub tshev tshiab tshwm ntawm koj lub desktop, thiab paub tseeb tias nws muaj cov ntawv" eclipse.exe "hauv nws. Nws yuav nug koj kom tsim chaw ua haujlwm thaum nws qhib. Sau "myWork" hauv lub npe bar, thiab nyem OK. Tom qab ntawd koj yuav tsum pom lub vijtsam zoo siab tos txais, thiab nyob rau sab xis saum toj nyem lub pob "workbench". Tam sim no koj yuav tsum pom qee yam zoo li daim duab 1 hauv qab. Tom qab ntawd nyem "Cov Ntaub Ntawv"> "Tshiab"> "Java Project". Hauv lub npov npe, ntaus "myProj", thiab nyem tom ntej, thiab tom qab ntawd ua tiav. Tam sim no, hauv qhov project explorer (sab laug ntawm lub vijtsam) koj yuav tsum pom daim nplaub tshev hu ua "myProj". Qhov project explorer yog qhov uas koj tuaj yeem pom tag nrho koj cov ntaub ntawv. Qhov chaw nyob hauv nruab nrab yog lub hauv paus ntsiab lus (ntu ntu) thiab sab xis yog Lub Tsev Qiv Ntawv, uas muab peb cov npe ntawm cov haujlwm thiab chav kawm. (Yuav tham txog chav kawm thiab kev ua haujlwm) tom qab). Cov hauv qab yog cov npe yuam kev, yog tias peb muaj teeb meem-sijhawm lossis teeb meem cov cai, lawv yuav nyob ntawd. Nws tseem yog lub qhov rai console qhov tso zis tau tshwm sim. Thaum kawg, nyem rau ntawm "myProj" nplaub tshev uas peb tsim thiab mus rau "Tshiab"> "Chav Kawm". Hauv lub npe bar hom "myFirst". Nyem tag. Koj yuav tsum pom daim duab thib 2 hauv qab kom pom zoo dua. Tam sim no koj tau npaj pib sau cov lej hauv JAVA. Hauv theem tom ntej peb yuav sau koj thawj qhov haujlwm, thiab tham txog qee yam ntawm JAVA.

Kauj Ruam 2: JAVA - Ua Haujlwm Nrog JAVA

JAVA - Ua Haujlwm Nrog JAVA
JAVA - Ua Haujlwm Nrog JAVA
JAVA - Ua Haujlwm Nrog JAVA
JAVA - Ua Haujlwm Nrog JAVA

Hauv JAVA, txhua yam yog ua raws chav kawm, ntu ntawm cov cai nrog cov lus txib kom ua. Kuj tseem muaj cov no hu ua cov txheej txheem, ntu me me ntawm cov cai uas muaj cov haujlwm ib yam nkaus. Feem ntau muaj ntau txoj hauv kev hauv chav kawm, uas cuam tshuam nrog ib leeg raws li qhov txiaj ntsig ntawm qee qhov kev hloov pauv thiab rov ua tus nqi. Cov txheej txheem ntawd tau ntim rau hauv chav kawm, thiab tom qab ntawv cov chav kawm nrog cov txheej txheem tuaj yeem cuam tshuam nrog lwm chav kawm thiab luam tus nqi rov qab los ntawm lub vijtsam. Kuj tseem muaj qee yam hu ua txoj hauv kev tseem ceeb, tus txheej txheem uas tus neeg sau ua ke tshawb nrhiav ua ntej. Raws li cov lus qhia txheej txheem tseem ceeb muab rau, tus neeg sau ntawv tuaj yeem txav mus rau cov chav sib txawv los ua txoj hauv kev sib txawv, lossis tsuas yog nyob hauv txoj hauv kev tseem ceeb. Txog tam sim no cia li tsim txoj hauv kev tseem ceeb. Hauv koj qhov "myFirst" chav kawm ntaus cov cai hauv qib siab: chav kawm pej xeem myFirst {pej xeem tsis muaj dab tsi zoo li qub (Txoj hlua args) {}} Tam sim no cia tham txog cov cai no. Txhua txoj hauv kev yog ua raws cov kab lus hauv qab no: [accessSpecifier] [returnType] [methodName] ([parameters]) {[methodBody]} Kev nkag mus tshwj xeeb hauv qhov no yog "pej xeem" thiab "zoo li qub". Txhua txoj hauv kev tuaj yeem yog "pej xeem" lossis "ntiag tug". "Pej Xeem" txhais tau tias txoj hauv kev tuaj yeem nkag mus los ntawm txhua chav kawm. "Ntiag Tug" txhais tau tias txoj hauv kev tuaj yeem nkag los ntawm tsuas yog chav kawm uas nws koom nrog. Kuv yuav piav qhia lo lus "Static" tom qab. Ntawm no peb tau tsim cov pej xeem zoo li qub txoj hauv kev nrog lub npe lub ntsiab, thiab cov ntsiab lus ntawm "String args" (Kuv yuav tsis piav qhia qhov tam sim no). Hauv tus txheej txheem lub cev peb ntaus txhua cov lus txib peb tsis xav ua. Tus txheej txheem lub cev thiab chav kawm lub cev ib txwm nyob nruab nrab ntawm cov zawm hniav. NCO TSEG: JAVA yog cov ntaub ntawv tsis nkag siab, yog li thaum koj sau cov lus txib, koj yuav tsum ntaus lawv raws li tau teev tseg, lossis koj yuav tau txais qhov yuam kev !!!!!! Tam sim no ntaus cov cai hauv qhov loj rau hauv koj txoj hauv kev tseem ceeb: pej xeem hauv chav kawm myFirst {pej xeem tsis muaj dab tsi zoo li qub (Txoj hlua args) {System.out.println ("Nyob zoo ntiaj teb!"); }} Txog tam sim no koj yuav tsum muaj cov cai hauv daim duab 1. Tam sim no mus rau "Khiav"> "Khiav", thiab nyem "OK" thaum lub npov lus tshwm, thiab hauv qab (console qhov rai) koj yuav tsum pom cov ntawv "Nyob zoo ntiaj teb!" luam tawm Kos daim duab thib ob rau siv. Ntawm no peb siv cov lus txib System.out.println los luam kab ntawm lub vijtsam. "System", yog chav kawm uas muaj ntau txoj haujlwm. Qhov "tawm" yog qhov peb xav luam tawm OUT mus rau lub vijtsam (lossis tso tawm) thiab cov txheej txheem "println" txhais tau tias; luam kab. Tom qab ntawd hauv cov kab ntawv, thiab hauv cov lus hais (vim tias qhov no yog txoj hlua muaj nuj nqis (tus nqi muaj cov lus)) peb suav nrog cov ntawv peb xav luam tawm, thiab xaus kab nrog ib nrab kab ntawv (;). NCO TSEG: Txhua kab hauv JAVA yuav tsum xaus rau ib nrab kab, tshwj tsis yog kab thaum peb tshaj tawm cov chav kawm lossis cov txheej txheem. Peb kuj tseem tuaj yeem siv "luam ntawv", tab sis qhov sib txawv ntawm "luam" thiab "println" yog tias "luam ntawv" luam cov ntawv ntawm kab, tab sis "println" txhais tau tias luam cov ntawv, thiab xaus kab, txhais tau tias yog tom ntej hais kom ua yog "luam tawm", cov ntawv yuav raug luam tawm ntawm kab tshiab. Txij ntawm no mus, Kuv xav thov zam txim rau qhov tsis zoo ntawm kuv cov duab. Kuv tau suav qee qhov SELF-CHECK cov lus nug hauv qab. Hauv cov kauj ruam tom ntej kuv yuav suav nrog cov lus teb rau lawv Hauv kauj ruam tom ntej no kuv tseem yuav qhia koj paub txog yam muaj nuj nqis. SELF-CHECK: #1) Sau qhov program kom luam lo lus "cheese" los ntawm tsab ntawv. HINT: Siv lo lus "print"#2) Siv "print" thiab "println" txib kom sim.#3) Dab tsi yog qhov tsis raug ntawm kab kab no: System.out.println (Nyob zoo ntiaj teb!); #4) Koj yuav tau txais dab tsi yog tias koj ua cov kab no ntawm cov cai: System.out.print ("h"); System.out.print ("kuv"); System.out.println ("ib-"); System.out.print ("tub");

Kauj Ruam 3: JAVA - Hom Kev Hloov pauv yooj yim

JAVA - Hom Kev Hloov Pauv Hloov Pauv
JAVA - Hom Kev Hloov Pauv Hloov Pauv
JAVA - Hom Kev Hloov pauv yooj yim
JAVA - Hom Kev Hloov pauv yooj yim

Cov lus teb rau cov lus nug SELF-CHECK yav dhau los yog:#1) System.out.print ("c"); System.out.print ("h"); System.out.print ("e"); System.out.print ("e"); System.out.print ("s"); System.out.print ("e"); #2) Tsis muaj lus teb meej.#3) Cov ntawv hauv kab zauv tsis nyob hauv cov lus hais tseg.#4) nyob zoo ib leeg Tus ntawd tseem yuav muaj tus kheej tshawb xyuas cov lus nug tom kawg ntawm cov theem no. Muaj ntau hom ntaub ntawv. Hauv cov lus qhia no peb yuav hla tsuas yog cov hauv paus, thiab nws tseem yuav ua ob peb kauj ruam. Txhua qhov sib txawv ua haujlwm ntawm cov kab lus hauv qab no. [DataType] [variableName] = [tus nqi]; qub. int kuvNum = 8; int hom: Hom "int", txhais tau tias yog integer. Ua haujlwm ntawm cov syntax tib yam li saum toj no. Tsis muaj cov lus hais xav tau los tuav tus nqi rau txhua hom lej. Txhua qhov kev hloov pauv sib txawv los ntawm qhov tsawg kawg ntawm -2, 147, 483, 648 mus rau tus nqi siab kawg ntawm 2, 147, 483, 647. Feem ntau cov lej sib txuam yuav haum rau hauv qhov no, tab sis yog lawv tsis siv "ntev" xwb. qub. int cuaj = 9; hom ntev: Hom "ntev" yog qhov ntev ntawm "int" hais kom ua. Cov qib ntawm -9, 223, 372, 036, 854, 775, 808 txog 9, 223, 372, 036, 854, 775, 807. hom ntab: Hom "ntab" yog tus lej ntab, uas txhais tau tias nws muaj tus lej zauv. hom ob: Hom "ob" yog tus lej-tus lej, uas tuaj yeem tuav tus nqi loj dua. hom hlua: Hom "hlua" tuav tus nqi ntawv. Cov ntawv (tus nqi) yuav tsum suav nrog hauv ob nqe lus. qub. Txoj hlua tos txais = "Nyob zoo"; Cov ntawd yog hom ntaub ntawv yooj yim. Txhawm rau luam tawm ib qho ntawm lawv tsuas yog sau lub npe sib txawv hauv qhov ntsuas ntawm "println" txoj kev tsis muaj nqe lus. qub. int kuvNum = 52930; System.out.println (myNum + "Yog tus nqi ntawm myNum"); Cov cai saum toj no yuav luam tawm "52930 Puas yog tus nqi ntawm myNum" ntawm qhov screen. Thiab los ntawm txoj kev peb siv muaj ib daim ntawv ntxiv rau ua ke ua ib txoj hlua rau kab peb tau luam tawm, yog li nws yuav luam tawm Txoj hlua tus nqi tom qab tus nqi ntawm myNum. Koj tuaj yeem siv daim ntawv ntxiv rau ntxiv cov ntawv hloov pauv hauv "println" hais kom ua thiab ntxiv cov hlua tseem ceeb. Txheeb tawm ob daim duab hauv qab kom pom tias kuv tau ua dab tsi. Qhov no yog ntu 1/2 ntawm tus lej naj npawb, hauv ntu tom ntej kuv yuav qhia koj qee tus lej ua lej yooj yim uas koj tuaj yeem siv ntawm qhov sib txawv.

Kauj Ruam 4: JAVA - Cov lej ua lej

JAVA - Cov lej ua lej
JAVA - Cov lej ua lej
JAVA - Cov lej ua lej
JAVA - Cov lej ua lej
JAVA - Cov lej ua lej
JAVA - Cov lej ua lej
JAVA - Cov lej ua lej
JAVA - Cov lej ua lej

Nov yog ntu 2/2 ntawm "Hom kev hloov pauv yooj yim". Ntawm no kuv yuav qhia cov lej ua lej. Muaj lub cim "+" uas txhais tau tias ntxiv. Nws yog siv los ntxiv cov lej. qub. cov sum = 5 + 579; Nws kuj tseem siv los ua ke cov hlua hauv "println" txoj kev. qub. System.out.println ("Qhov no yog" + "peb txoj hlua" + "ua ke."); Daim ntawv ceeb toom tias ua ntej ntxiv lwm txoj hlua ntawm thawj thiab ob txoj hlua kuv tau siv qhov chaw nyob rau qhov kawg kom nws zoo li qub. Kuj tseem muaj tus cim "-" raws li koj tau twv, thiab nws tsuas yog siv los rho cov lej. qub. int rho = 9 - 6; Tsis tas li ntawd muaj tus lej ua haujlwm sib npaug, uas sawv cev los ntawm "*" hauv java (asterisk). Nws yog siv los ua lej. qub. sib npaug = 756 * 15; Thiab muaj cov neeg ua haujlwm faib, uas sawv cev los ntawm "/" (slash). Nws yog siv los faib cov lej. qub. int faib = 50 /5 Tsis tas li ntawd muaj tus neeg teb xov tooj modulo, uas sawv cev los ntawm "%". Modulo tau siv los tsom mus rau seem ntawm ob tus lej, yog tias muaj. qub. int modulo = 10 % 9; cov. Koj tsis tas yuav ntxiv cov lus hais rau tus lej yog tias koj siv tus lej hauv "println" txoj kev, lossis lawv yuav raug txhais raws li txoj hlua tseem ceeb. qub. System.out.println (6 + 7); ZOO TSHAJ PLAWS 1: System.out.println ("6" + "7"); Cov cai saum toj no rov qab 67, tsis yog 13. Txhawm rau zam qhov no rho tawm cov lus. Cov npe sib txawv tuaj yeem siv los txheeb xyuas qhov muaj nuj nqis. Xws li: int myNum = 9; System.out.println ("Tus nqi ntawm myNum yog" + myNum); Tsuav "myNum" tsis muaj qhov hloov pauv nyob ib puag ncig nws, txoj haujlwm yuav luam tawm "Tus nqi ntawm myNum yog 9". Koj kuj tseem tuaj yeem siv cov neeg ua haujlwm los ua haujlwm hauv "println" txoj hauv kev kom rov qab tau cov txiaj ntsig tau sai. qub. System.out.println (8 * 10); Kuv cov duab yuav yog qhov tseem ceeb ntawm txhua yam peb tau hais hauv ntu no, tab sis tsis txhob hnov qab tshuaj xyuas lawv. Hauv kauj ruam tom ntej yuav muaj cov khoom siv me me me, tab sis yuav muaj qhov kev xeem uas npog txhua yam peb tau kawm txog tam sim no. Nov yog cov lus nug tus kheej: SELF-CHECK #1: Sau qhov program los laij cov lej ntawm 789 txog 2, thiab luam tawm qhov tshwm sim ntawm qhov screen. SELF-CHECK #2: Piav qhia hom "int" cov ntaub ntawv, yam tsawg kawg yog tus yam ntxwv tseem ceeb. SELF-CHECK #3: Tsim txoj hlua sib txawv hu ua "txais tos" nrog cov lus zoo hauv nws tawm ntawm lub npe (ex. Nyob zoo _). Tom qab ntawd tsim txoj hlua hu ua "npe" nrog tus nqi ntawm koj lub npe. Tom qab ntawd ua ke cov kev hloov pauv no thiab koj yuav tsum tau txais koj cov lus kawg. SELF-CHECK #4: Koj sawv cev ua tus lej hauv JAVA li cas? (Koj siv tus cim dab tsi)

Kauj Ruam 5: JAVA - Kev Xeem Ua Thawj / Hais Lus

JAVA - 1st Test / Commenting
JAVA - 1st Test / Commenting

Nov yog cov lus teb rau cov lus nug SELF-CHECK yav dhau los:#1) System.out.println (789 % 2); #2) Cov ntaub ntawv "int" tuav ib tus lej.#3) Txoj hlua tos txais = "Nyob Zoo"; Txoj hlua lub npe = "JAVA Xib Fwb" System.out.println (txais tos + npe); #4) Koj siv "*" (asterisk) OK, tam sim no rau cov lus qhia no Kuv tsuas yog suav nrog cov khoom tshiab me ntsis, thiab txuas rau kuv qhov kev xeem. Hauv JAVA muaj qee yam hu ua "tawm tswv yim". Qhov ntawd txhais tau tias tawm tswv yim txog koj txoj haujlwm. Muaj 2 hom kev tawm tswv yim koj tuaj yeem hais tawm ib leeg-kab lus (saib ex. 1) thiab ntau kab lus (saib ex. 2). Cov piv txwv rau cov lus pom no suav nrog. Rau ib kab lus tawm tswv yim koj yuav tsum tso 2 qhov sib luag ua ntej cov ntawv, txhua yam mus rau sab xis ntawm qhov kev txiav tawm yog suav tias yog lus tawm, thiab tsis quav ntsej los ntawm JAVA tus neeg sau. Ib qho yooj yim kab lus tawm tswv yim yog nyob nruab nrab ntawm cov hlais thiab 2 lub hnub qub, thiab xaus nrog lub hnub qub thiab lub ntsej muag. Kev tshaj tawm kab lus ntau tshaj piav qhia txog txoj hauv kev, peb yuav hla qhov no tom qab. JAVA ADVICE: Kuv qhia koj kom tawm tswv yim txhua yam, txawm tias qhov yooj yim tshaj plaws. Vim tias yog qee tus neeg dhau los ntawm koj txoj haujlwm thiab tej zaum yuav muaj teeb meem nkag siab koj cov cai. Nws yuav tsis pom tseeb tias qhov sib txawv d sawv rau duas. Thiab kuv kuj qhia koj kom txuag koj txoj haujlwm ntau zaus. (Kuv poob ntau tus lej vim qhov no ib zaug) ex. 1 int num2 = 78; // Tsim tus lej, "num2" nrog tus nqi ntawm 78 ex. 2 / ** Tsim cov lej, "num2" nrog tus nqi 78* / int num2 = 78; OK, hmoov zoo ntawm qhov kev xeem.:-) (LINK AT BOTTOM, NYEEM NTAWV) CEEB TOOM: Kuv yeej maj nrawm los ntawm kev xeem ntawv, yog li ntawm #2 Kuv cim cov lus teb tsis raug raws li qhov raug. Cov lus teb raug rau qhov ntawd yog qhov kev xaiv zaum kawg. Kuv thov txim ntau rau qhov tsis yooj yim no. Qhov txuas rau qhov kev xeem nyob ntawm no. Muaj ib daim duab nyob hauv qab ntawm lub vijtsam txais tos ntawm qhov kev xeem ib yam nkaus.:-)

Pom zoo: