我觉得很简单啊:1、全部小写
2、开始从前往后遍历,先将第一个字母大写;
3、看到“.”后将后面的第一个字母大写。Over

解决方案 »

  1.   

    各位大虾,小弟请教一个问题:
     如何把java程序发布出去,添加到“程序”组里
      

  2.   

    老师的要求肯定是要求你们遍历String了。通过String的getBytes方法取得数组做吧!
      

  3.   

    你也不一非按老师的说的去遍历呀 
    1、你可以先把他变为小写,
    2、StreamTokenizer来按"."分串 然后把每一个子串的首字符大写
      

  4.   

    先试一试这个(我都调试通过的),以后再给StreamTokenizer的例子:String str="bird-watchers   LOVE to       watch birds.birds don't liKE   being watched,so bird-watchers   build boxes,called \"hides\"  ,in which they    can hide While they watch the         birds  .";
    System.out.println(str);
    str.trim();
    str=str.toLowerCase();
    byte [] b;
    byte [] b1;
    boolean dot=false,comma=false,space=false;
    byte flag;
    int i=0,j=0;
    try{
             b=str.getBytes();
    b1= new byte[str.length()+30];
    b1[j++]=( byte )( ( int )( b[i++] ) - 32 );
    flag=b1[j-1];
    while(i<b.length && j<b.length+30)
    {
                  switch(flag){
    case '.': b1[j++]=' ';
      b1[j++]=' ';
      while(b[i]==' ') i++;
      b1[j++]=( byte )( ( int )( b[i++] ) - 32 );
      flag=b1[j-1];;
      break;
    case ',':b1[j++]=' ';
      while(b[i]==' ') i++;
      b1[j++]=b[i++];
      flag=b1[j-1];
      break;
    case ' ':while ( b[i]==' ' ) i++;
      if(b[i]==',' || b[i]=='.') j--;
      b1[j++]=b[i++];
      flag=b1[j-1];
      break;
      default:b1[j++]=b[i++];
      flag=b1[j-1];
    }
    }
    String str1=new String(b1);
    System.out.println(str1);
    }
    catch(Exception e){
    System.out.println(flag);
    System.out.println(i);
    System.out.println(j);
    e.printStackTrace(System.out);
    }