{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Chapter 6 - CompSci 121 Test Review 1 Chapter 5 Methods...

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

View Full Document Right Arrow Icon
int j = 1; while (j <= 5){ System.out.println(j); j = j + 1; } int left = 0; int right = letters.length() - 1; boolean ok = true ; while (left < right){ if (letters.charAt(left) != letters.charAt(right)) {ok = false ; break ;} / / immediately terminates loop left++; right--; } return ok; } { switch (ch) { case 'a': case 'e': case 'i': case 'o': case 'u': System.out.println( "vowel" ); break ; case 'y': System.out.println( "vowel or consonant" ); break ; default : System.out.println( "consonant" ); } } } I nfinite Loop Example: int k = 1; while (k != 10){ System.out.println(k); k = k + 2; } Do Statement Example: int k = 0; do { k = k + 1; System.out.println(k); } while (k < 5); int k; do { System.out.println( "enter a non-zero value" ); k = scan.nextInt(); } while (k == 0); CompSci 121 Test Review 1 Chapter 5 Methods - Java’s 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 method’s 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 - Control Variable – A variable the controls the loop body executes - Test Condition – A boolean valued gate-keeper in a loop. As long as the test
Image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern