是我的话会把那个指定位置的字符substring提出来比如赋给String a 然后Integer.parseInt(a); 加上小写和大写的ascii差值 再转成字符
public String upperCase(String str, int pos) { return str.substr(0, pos) + str.substr(pos, pos+1).toUpperCase() + str.substr(pos+1); }
public class UpperCase { public static void main(String[] args) { System.out.println(getTheUpperCase("good", 0)); } static String getTheUpperCase(String src, int pos) { if(pos>=src.length()) throw new RuntimeException("指定的位置不合法!");
然后Integer.parseInt(a);
加上小写和大写的ascii差值
再转成字符
return str.substr(0, pos) + str.substr(pos, pos+1).toUpperCase() + str.substr(pos+1);
}
public class UpperCase { public static void main(String[] args) { System.out.println(getTheUpperCase("good", 0)); }
static String getTheUpperCase(String src, int pos)
{
if(pos>=src.length())
throw new RuntimeException("指定的位置不合法!");
StringBuilder sb = new StringBuilder(src);
sb.setCharAt(pos, Character.toUpperCase(src.charAt(pos)));
return sb.toString();
}
}
{
if(pos < 1 || pos > str.length() || null == str | "".equals(str)) return null;
char[] strChars = str.toCharArray();
strChars[pos-1] = Character.toUpperCase(strChars[pos-1]);
return String.valueOf(strChars);
}
{
if(pos < 1 || pos > str.length() || null == str | "".equals(str)) return null;
char[] strChars = str.toCharArray();
strChars[pos-1] = Character.toUpperCase(strChars[pos-1]);
return String.valueOf(strChars);
}