Chapter 6 - int j = 1; while (j <= 5){...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: int j = 1; while (j <= 5){ System.out.println(j); j = j + 1; } int left = 0; int r ight = letters.length() - 1; boolean ok = tr ue ; while (left < r ight){ if (letters.charAt(left) != letters.charAt(r ight)) {ok = false ; br eak ;} / / immediately terminates loop left++; r ight--; } r etur n ok; } { switch (ch) { case 'a': case 'e': case 'i': case 'o': case 'u': Syst em.out.pr intln( "vowel" ); br eak ; case 'y': System.out.pr intln( "vowel or consonant" ); br eak ; default : Syst em.out.pr intln( "consonant" ); } } } I nfinite Loop Example: int k = 1; while (k != 10){ Syst em.out.pr intln(k); k = k + 2; } Do Statement Example: int k = 0; do { k = k + 1; Syst em.out.pr intln(k); } while (k < 5); int k; do { Syst em.out.pr intln( "ent er a non-zero value" ); k = scan.nextI nt(); } while (k == 0); CompSci 121 Test Review 1 Chapter 5 Methods- Javas mechanism for combining elementary actions for the purpose of doing some larger job- Default Constructor Used when there is no explicit constructor- When writing methods, clarity and readability are highly prized- Major components of a method o Header Line Gives methods visibility Return Type Declaration type Method Name Parameter List: Type followed by formal parameter o Method Body Computation type performs method equation Return Statement passes returned value out of method Chapter 6 While Loops...
View Full Document

This note was uploaded on 03/17/2009 for the course COMPSCI 121 taught by Professor Miller during the Spring '08 term at UMass (Amherst).

Page1 / 5

Chapter 6 - int j = 1; while (j <= 5){...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online