Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static String getMiddle(String str)
- {
- if (str.length() == 0) { return ""; }
- if(str.length() % 2 == 0)
- {
- double middle = str.length() / 2;
- return String.format("%c%c", str.charAt((int)(middle - .5)), str.charAt((int)(middle + .5)));
- }
- else
- {
- return String.format("%c", str.charAt(str.length() / 2));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement