| .
|
Lab 3.2 Solution:
// This solution shows a type-method that you
// would need to call from another method.
String reverseThreeWordString(String phrase) {
String result;
String wordA,wordB,wordC,remaining;
int begin,end;
remaining=phrase;
begin=0;
end=remaining.indexOf(" ");
wordA=remaining.substring(begin,end);
begin=end+1;
remaining=remaining.substring(begin,remaining.length());
begin=0;
end=remaining.indexOf(" ");
wordB=remaining.substring(begin,end);
begin=end+1;
wordC=remaining.substring(begin,remaining.length()) ;
result=wordC+" "+wordB+" "+wordA;
return result;
}
|