package JZoffer; public class JZ2 { public String replaceSpace (String s) { // write code here if (s == null || s.length() == 0){ return ""; } if (s.length() == 1 && s.equals(" ")){ return "%20"; } String[] fields = s.split(" "); StringBuilder sb = new StringBuilder(); if (fields.length == 0){ for (int i = 0; i < s.length(); i++) { sb.append("%20"); } }else { for (int i = 0; i < fields.length - 1; i++) { sb.append(fields[i] + "%20"); } sb.append(fields[fields.length-1]); if (s.charAt(s.length()-1) == ' '){ sb.append("%20"); } } return sb.toString(); } }