1.先取得第i个字符:
   int i=3;
   String str="abcdefg";
   char temp=str.charAt(i);
2.在利用char的wrapper类Character的工具;
   str=str.substring(0,i)+Character.toUpperCase(temp)
             +str.substring(i+1,str.length());
   system.out.println("The new string is "+str);

解决方案 »

  1.   

    先转换小写,然后找空格,用toUpperCase()和substring
      

  2.   

    import javax.swing.*;public class Sos1
    {
       public static void main(String[] args)
       {
          String s1 = "abcdefg";
          
          String num = JOptionPane.showInputDialog("Which characters do you want to change?");
          int i = Integer.parseInt(num)-1;
          String temp1 = s1.substring(i,i+1);
          String temp2 =temp1.toUpperCase();
          String temp3 = s1.substring(0,i);
          String temp4 = s1.substring(i+1);
          String newstring = temp3+temp2+temp4;
          System.out.println(newstring);      System.exit(0);
           
       }
    }我也是新手,写的不好,多包涵!
      

  3.   

    String str="abcdefg";
    String ch= str.subString(i,i+1);
    ch.toUpperCase();
    StringBuffer sb=new StringBuffer(str);
    sb.setCharAt(i,ch.charAt(0));
    str=sb.toString();
      

  4.   

    String str="abcdefg";
    StringBuffer sb=new StringBuffer(str);
    sb.setCharAt(i,Character.toUpperCase(str.charAt(i)));
    str=sb.toString();