This is an assignment that one
of my friends professors gave to the class.
He wanted me to help him so i figured ok.
The decription of the assignment is down below,
but i am having trouble with this statement
while((q = x % key.length()) != ???????){
which is also down below. Any help would be cool.
Code:create a method that takes
a String as an arguement and
returns a TreeMapwhich will map
the string and the number of
characters that occur only once
within the string. since the counting
operation can be time consuming, the
method should cache the results so that
when the method is given a string
previously encountered,it
will simply retrieve the stored result.
import java.io.*;
import java.util.*;
public class MultipleChar{
public static void main(String[] args){
for(;;){
BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
try{
System.out.println("Please enter a string");
String key = buff.readLine();
TreeMap tm = (TreeMap) checkForDuplicates(key);
System.out.println(" Within " + key + " there were " + tm.get(key) + " characters that only appeared once ");
System.out.println("Press Y if you would like to continue: " + "N if you want to exit" );
String exit = buff.readLine();
if(exit.equalsIgnoreCase("n")){System.exit(0);}
}catch(Exception e){System.err.println(e);}
}
}
public static Object checkForDuplicates(String key){
short onlyappearsonce;
short duplicates = 0;
char matchingchar;
Map stringMap = new TreeMap();
int q = 1;
int z = 0;
int x = 0;
int k = 0;
short multiplechar;
// check map to see if string is present, if it is return key
if(stringMap.containsKey(key)){return stringMap.get(key);}
for(int index = 0; index <= key.length() - 1; ++index){
matchingchar = key.charAt(index);
x = ((key.length() * key.length()) - (key.length() + 1));
System.out.println(x);
while((q = x % key.length()) != ???????){
if(matchingchar == key.charAt(++z)){
++duplicates;
}
--x;
}
z = 0;
z =+1;
}
int nonduplicatechars = (key.length() - duplicates);
Integer charcount = new Integer(nonduplicatechars);
stringMap.put(key,charcount);
return stringMap;
}
}
