Cov txheej txheem:

Dab tsi yog qhov hloov pauv hauv Java?
Dab tsi yog qhov hloov pauv hauv Java?

Video: Dab tsi yog qhov hloov pauv hauv Java?

Video: Dab tsi yog qhov hloov pauv hauv Java?
Video: Uv koj los laus tsis zoo dab tsi by nkaujnoog hawj 2024, Hlis ntuj nqeg
Anonim

hloov nqe lus hauv java . Kev tshaj tawm. A hloov nqe lus tso cai rau qhov sib txawv los ntsuas qhov sib npaug ntawm cov npe ntawm cov txiaj ntsig. Txhua tus nqi hu ua a cas , thiab qhov hloov pauv hloov tau raug kuaj xyuas rau txhua tus cas.

Xav txog qhov no, hloov rooj plaub txhais li cas hauv Java?

Qee cov cai tseem ceeb rau kev hloov cov nqe lus:

  1. Tsis pub muab cov ntaub ntawv sib npaug.
  2. Tus nqi rau ib rooj plaub yuav tsum yog tib hom ntaub ntawv raws li qhov sib txawv hauv qhov hloov.
  3. Tus nqi rau ib rooj plaub yuav tsum yog qhov tsis tu ncua los yog qhov tseeb.
  4. Cov lus hais tawm yog siv nyob rau hauv qhov hloov mus rau qhov xaus ib nqe lus ib ntus.

Tsis tas li ntawd, ua li cas koj sau ib rooj plaub hloov? Cov cai rau kev hloov pauv lus:

  1. Ib qho kev qhia yuav tsum ua tiav rau qhov tshwm sim.
  2. Case labels yuav tsum tsis tu ncua thiab tshwj xeeb.
  3. Cov ntawv cim yuav tsum xaus nrog lub plab (:).
  4. Ib lo lus tseem ceeb so yuav tsum muaj nyob rau hauv txhua rooj plaub.
  5. Muaj peev xwm tsuas muaj ib daim ntawv lo.
  6. Peb tuaj yeem tsim ntau cov lus qhia hloov.

Ib yam li ib tug yuav nug, Yuav ua li cas Hloov cov ntaub ntawv siv hauv Java nrog piv txwv?

// Java Program los ua kom pom cov piv txwv ntawm Hloov nqe lus.

Piv txwv:

  1. Public class SwitchExample {
  2. public static void main(String args) {
  3. // Tshaj tawm qhov sib txawv rau kev hloov pauv.
  4. int num=20;
  5. // Hloov qhia.
  6. hloov (tus lej) {
  7. // Cov ntsiab lus ntawm rooj plaub.
  8. Case 10: System. tawm. println("10");

Muaj pes tsawg tus neeg tuaj yeem hloov daim ntawv qhia muaj nyob hauv Java?

Java Switch Statement Piv txwv hauv lub hloov nqe lus yog 3 cov lus hais thiab lub neej ntawd nqe lus . Txhua case lus piv tus nqi ntawm tus nqi sib txawv nrog tus nqi tas li. Yog tias tus nqi sib txawv ntawm tus nqi sib npaug ntawm tus nqi tas li, cov cai tom qab txoj kab (:) raug tua.

Pom zoo: