Posted By

Aseliot on 10/17/13


Tagged


Versions (?)

Java return middle (broke?)


 / Published in: Java
 

Doesnt work, asking somewhere else why

  1. public static String middle(String str)
  2. {
  3. if(str.length()%2 == 0)//even
  4. {
  5. String substr = str.substring((str.length()/2),(str.length()/2+1));
  6. substr = substr + str.substring((str.length()/2+1),(str.length()/2+2));
  7. }
  8. else //uneven
  9. {
  10. String substr = str.substring((int)Math.floor(str.length()/2), (int)Math.floor(str.length()/2+1));
  11.  
  12. }
  13. return substr;
  14. }

Report this snippet  

You need to login to post a comment.