/* EXPECTED OUTPUT: (run #1) Type two words: car STAR They rhyme! EXPECTED OUTPUT: (run #2) Type two words: bare bear They alliterate! EXPECTED OUTPUT: (run #3) Type two words: sell shell They alliterate! They rhyme! */ // Tells whether two words alliterate by comparing their first letters, // and whether they "rhyme" by comparing their last two letters. 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(); word1 = word1.toLowerCase(); word2 = word2.toLowerCase(); if (word1.charAt(0) == word2.charAt(0)) { System.out.println("They alliterate!"); } String lastTwo1 = word1.substring(word1.length() - 2, word1.length()); String lastTwo2 = word2.substring(word2.length() - 2, word2.length()); if (lastTwo1.equals(lastTwo2)) { System.out.println("They rhyme!"); } } }