Wednesday 15 September 2010

Java Method is broken -



Java Method is broken -

i trying homecoming compressed word. example, reaction should @act$. getting returned react$. sense issue not including original word in homecoming statement. can help? thanks!

public static string compress (string word) { string newword = ""; int = word.indexof("the"); if (the >= 0) { newword = word.substring(0,the) + "&" + word.substring(the+3); } int ion = newword.indexof("ion"); if (ion >= 0) { newword = newword.substring(0,ion) + "$" + word.substring(ion+3); } int ing = newword.indexof("ing"); if (ing >= 0) { newword = newword.substring(0,ing) + "~" + word.substring(ing+3); } int = newword.indexof("an"); if (an >= 0) { newword = newword.substring(0,an) + "#" + word.substring(an+2); } int re = newword.indexof("re"); if (re >= 0) { newword = newword.substring(0,re) + "@" + word.substring(re+2); } int con = newword.indexof("con"); if (con >= 0) { newword = newword.substring(0,con) + "%" + word.substring(con+3); } homecoming newword; }

a compressed version also:

public static string compress(string word) { word = word.replace("the", "&"); word = word.replace("ion", "$"); word = word.replace("ing", "~"); word = word.replace("an", "#"); word = word.replace("re","@"); word = word.replace("con","%"); homecoming word; }

java methods return compression static-methods

No comments:

Post a Comment