// Determines whether two words rhyme and/or alliterate. 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().toLowerCase(); String word2 = console.next().toLowerCase(); printIfRhyme(word1, word2); printIfAlliterate(word1, word2); } // print if two words "rhyme" (i.e., end with the same two letters) public static void printIfRhyme(String word1, String word2) { if (word2.length() >= 2 && word1.endsWith(word2.substring(word2.length() - 2))) { System.out.println("They rhyme!"); } } // print if two alliterate public static void printIfAlliterate(String word1, String word2) { if (word1.startsWith(word2.substring(0, 1))) { System.out.println("They alliterate!"); } } }