当前位置: 技术问答>java相关
老师布置的一道题目,把文本里面字母大小写改正确?求解
来源: 互联网 发布时间:2017-03-26
本文导语: 例如,在一个JTextArea里,程序输入是 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 . 程...
例如,在一个JTextArea里,程序输入是
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 .
程序输出在另外一个JTextArea里,要求每句第一个字母大写,其余小写,逗号后面空一格,句号后空两格,程序输出应该为:
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.
老师说重复使用一些JAVA API的类可以很方便地解决这道题,请问有没有比较方便的解决办法?
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 .
程序输出在另外一个JTextArea里,要求每句第一个字母大写,其余小写,逗号后面空一格,句号后空两格,程序输出应该为:
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.
老师说重复使用一些JAVA API的类可以很方便地解决这道题,请问有没有比较方便的解决办法?
|
先试一试这个(我都调试通过的),以后再给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
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
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
站内导航:
特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!