// Marty Stepp, CSE 142, Spring 2010 // Determines whether two words rhyme (end w/ same last 2 letters) // and/or alliterate (start with the same letter). import java.util.*; public class Rhyme { public static void main(String[] args) { Scanner console = new Scanner(System.in); System.out.print("Type two words: "); String word1 = console.next(); String word2 = console.next(); // index 01234 // word1 = "Marty" if (word1.length() >= 2 && word2.length() >= 2) { // check whether they rhyme (end w/ same last 2 letters) String lastTwo1 = word1.substring(word1.length() - 2); String lastTwo2 = word2.substring(word2.length() - 2); if (lastTwo1.equalsIgnoreCase(lastTwo2)) { System.out.println("They rhyme!"); } } // check whether they alliterate (start w/ same letter) String firstLetter2 = word2.substring(0, 1).toLowerCase(); if (word1.toLowerCase().startsWith(firstLetter2)) { System.out.println("They alliterate!"); } } }