Link to home
Start Free TrialLog in
Avatar of gudii9
gudii9Flag for United States of America

asked on

java string challenge to display

Hi,

I am working on below coding challenge
http://codingbat.com/prob/p130781
i wrote as below


public String right2(String str) {

return str.substring((str.length())-2)+str.substring(0,str.length()-2);
  
}

Open in new window

i would like to know how can improve on my above code. Please advise.Thanks in advance
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gudii9

ASKER

public String right2(String str) {
int len=str.length();
return str.substring(len-2)+str.substring(0,len-2);
  
}

Open in new window


i like idea of creating variable to compute once as above
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial