Week7Chap4-v

Week7Chap4-v - Chapter 4 Selection and Repetition...

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

View Full Document Right Arrow Icon
Janaka Balasooriya CSE 110, Arizona State University Chapter 4 Selection and Repetition Applications
Background image of page 1

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

View Full DocumentRight Arrow Icon
Nested Loops Similar to nested if statements, loops can be nested as well That is, the body of a loop can contain another loop For each iteration of the outer loop, the inner loop iterates completely
Background image of page 2
PalindromeTester.java //******************************************************************** // PalindromeTester.java Java Foundations // // Demonstrates the use of nested while loops. //******************************************************************** import java.util.Scanner; public class PalindromeTester { //----------------------------------------------------------------- // Tests strings to see if they are palindromes. //----------------------------------------------------------------- public static void main (String[] args) { String str, another = "y"; int left, right; Scanner scan = new Scanner (System.in); while (another.equalsIgnoreCase("y")) // allows y or Y { System.out.println ("Enter a potential palindrome:"); str = scan.nextLine();
Background image of page 3

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

View Full DocumentRight Arrow Icon
PalindromeTester.java left = 0; right = str.length() - 1; while (str.charAt(left) == str.charAt(right) && left < right) { left++; right--; } System.out.println(); if (left < right) System.out.println ("That string is NOT a palindrome."); else System.out.println ("That string IS a palindrome."); System.out.println(); System.out.print ("Test another palindrome (y/n)? "); another = scan.nextLine(); } } }
Background image of page 4
Chapter 4: More Practice Questions • 4.4, 4.5, 4.7, 4.8, 4.22, 4.21 • Quiz 4 solutions • In-class activity 8
Background image of page 5

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

View Full DocumentRight Arrow Icon
Janaka Balasooriya CSE 110, Arizona State University Chapter 5 Writing Classes
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/08/2010 for the course CSE 110 taught by Professor Kim during the Spring '08 term at ASU.

Page1 / 12

Week7Chap4-v - Chapter 4 Selection and Repetition...

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

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