1 / 13

TINGIMUSED JA TSÜKLID

TINGIMUSED JA TSÜKLID. Loogilised tehted ja avaldised. && ja true && true  true true && false  false false && true  false false && false  false || või true || true  true true || false  true false || true  true false || false  false. ! eitus

arin
Download Presentation

TINGIMUSED JA TSÜKLID

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. TINGIMUSED JA TSÜKLID

  2. Loogilised tehted ja avaldised && ja true && true  true true && false  false false && true  false false && false  false || või true || true  true true || false  true false || true  true false || false  false ! eitus !false  true !true  false • Loogilisi avaldisi: • true • false • x <= 1 • (a – 1) == b • c != (a + 2) • !((x < 0) || (x > 1)) • onÜhiklõigul(x - y)

  3. TSÜKLIDIREKTIIVID

  4. Üldtsüklidirektiiv * 7 (korrata 7 korda) väljastada(“Tere!”) * i = 5, 6, ..., 9 (korrata iga i korral, i = 5,6,...,9) väljastada(i) * i = 1, 2, ..., 9 (korrata iga i korral, i = 1,2,...,9) i väljastada(2) Näiteprogramm: Pr3_3.java

  5. Üldtsüklidirektiiv: for(i=5; i<10; i++){ System.out.println(i); } i = 5 i<10? System.out.println(i) i++ A B C – + S A - eeltegevus(ed) B - loogiline avaldis (jätkamistingimus) C - sammu järeltegevus(ed) S - sisu

  6. Üldtsüklidirektiiv: for(A; B; C){ S }//for A B? S C – + A - eeltegevus(ed) B - loogiline avaldis (jätkamistingimus) C - sammu järeltegevus(ed) S - sisu

  7. Eelkontrolliga tsüklidirektiiv: while(B){ S }//while B? S – + B - loogiline avaldis (jätkamistingimus) S - sisu Näiteprogramm: Pr3_4.java

  8. Järelkontrolliga tsüklidirektiiv: do { S } while(B); S B? – + B - loogiline avaldis (jätkamistingimus) S - sisu Näiteprogramm: Pr3_5.java

  9. TINGIMUSDIREKTIIVID

  10. Tingimusdirektiiv (if ... ) if( loogiline avaldis){ … “kui-siis” osa } false loog. av. true … “kui-siis” osa loogiline avaldis ? … “kui-siis” osa

  11. Tingimusdirektiiv (if ... else) if( loogiline avaldis){ … “kui-siis” osa } else{ … “muidu” osa } false loog. av. true … “kui-siis” osa loogiline avaldis ? … “kui-siis” osa … “muidu” osa … “muidu” osa

  12. Programm ühiklõigul kahe juhuarvu leidmiseks, mille ruutude summa ei ole ühiklõigul. Juhu2 main( ) onÜhiklõigul( ) • Meetod random( ) klassist Math • double x = Math.random(); • // 0 <= x < 1 • int y = (int)(Math.random()*11); • //y väärtus on üks arvudest 0,1,2,...,10 Programm Juhu2.java

  13. Hääldusjuhiseid boolean[buliʌn ] – Boole’i; loogiline true [tru] – tõene; jah false [fɔːls] – väär; ei if [ɪf ] – kui; tingimusel, et else [els] – vastasel korral; muidu while [waɪl] – seni, kuni random [rændʌm] – juhuslik; juhu-

More Related