/* Lesley Hogan * July 28th 2003 * StringMethods.java * Stuff with strings * Homework from: * http://teachertech.rice.edu/Participants/marilynt/Lessons/Exeter/Programming/stringPrac.html */ package net.bunnie.dos; import net.bunnie.*; public class StringMethods { public static void main (String[] args) { char present; int words = 0; String input; String inputChar; String isPresent = "Not present"; String[] modified = new String[4]; KeyboardReader r = new KeyboardReader(); Echo.e("Please input a sentence: "); input = r.readLine(); Echo.e("Please input a character: "); inputChar = r.readLine(); present = inputChar.charAt(0); Echo.e("\n"); modified[0] = input.toUpperCase(); modified[1] = input.toLowerCase(); modified[2] = ""; for (int i = 0; i <= input.length() - 1; i++) { if (input.charAt(i) == ' ') { modified[2] += input.charAt(i); words++; } else { modified[2] += input.charAt(i) + " "; } if (input.charAt(i) == present) { isPresent = "Present"; } } words++; modified[3] = ""; for (int i = input.length() - 1; i >= 0; i--) { modified[3] += input.charAt(i); } Echo.e("Sentence uppercase: " + modified[0] + "\n"); Echo.e("Sentence lowercase: " + modified[1] + "\n"); Echo.e("Sentence backwards: " + modified[3] + "\n\n"); Echo.e("Sentence with one space in between letters and two spaces in between words:\n" + modified[2] + "\n\n"); Echo.e("The letter " + present + " is: " + isPresent + "\n"); Echo.e("Number of words in sentence: " + words + "\n\n"); } }