Switch to full style
Java2 codes,problems ,discussions and solutions are here
Post a reply

Java Anagram

Mon Jul 20, 2009 3:06 am

Two words or phrases in English are anagrams if their letters, rearranged, are the same. We assume that upper and lower case are indistinguishable, and punctuation and spaces don't count. Some examples and non-examples:

* The eyes / they see (yes)
* moo / mo (no)
* Clint Eastwood / Old west Action! (yes)
* Dormitory / Dirty Room (yes)



Your job for this assignment: Write a two class application that reads in two words or phrases from the keyboard, and then judges if the two are anagrams.

(Note: this is a work-alone assignment. You may consult with others on design, etc., but you must submit your own work! Do not - repeat do not - submit the same solution as another student!).

The classes should be called: AnagramDriver, and Anagram

Some tips:

* use the String methods toLowerCase() and toCharArray(). The former takes all letters in a String and changes them to lower case; the latter converts a String into an array of characters.

* Very important: suppose you have two arrays of characters that are purported to be anagrams of each other. How do you tell? The single most important thing to do, before you write a single line of code, is to work out a paper and pencil algorithm that satisfactorily distinguishes between anagrams and non-anagrams.

* Your classes must be commented! In particular, each method must have a one line comment just below the header line, which tells what the method is supposed to do.

* Algorithm Idea #1: make a scoreboard for the letters a to z. Every time you encounter a letter in the first String, up its count by 1; Every time you encounter a letter in the second String, lower its count by 1. Accept if the scoreboard ends up as all 0s;

* Algorithm Idea #2: convert strings to arrays. March down first String. When you encounter a letter, look for it in the second String. If you find it, blank it out; if you don't find it - not anagrams. When you're all done, you've got anagrams if the second array contains no letters.



Re: Java Anagram

Tue Jul 21, 2009 11:42 am

Assignment ?? lol .

Re: Java Anagram

Mon Sep 26, 2011 5:05 pm

java/anagram-in-java-t7720.html

Post a reply
  Related Posts  to : Java Anagram
 anagram in java     -  
 2d game in java-Monster-Java 2D Game Graphics and Animation     -  
 need help in java     -  
 What is Java API?!!!     -  
 Using FTP in java     -  
 java or .net     -  
 what is java     -  
 Java course     -  
 XOR Mode in java     -  
 Java Servlet and JSP     -