java 将字符串中每个单词的首字母大写,运行的时候只显示了一个单词,怎么回事
importjava.util.*;publicclassCapitalize{publicstaticvoidmain(Stringargs[]){Stringstr;...
import java.util.*;
public class Capitalize{
public static void main(String args[]){
String str;
char c,d;
Scanner keyboard=new Scanner(System.in);
System.out.println("This program is compiled by GaoQinghong.");
System.out.print("Enter a string -> ");
str= keyboard.next();
System.out.println("After compitalize:");
for(int i=0;i<str.length();i++){
c=str.charAt(i);
if(i==0)
{
if(Character.isLetter(c)){
System.out.print( Character.toUpperCase(c));
}
if(!Character.isLetter(c))
System.out.print(c);
}
if(i!=0){
d=str.charAt(i-1);
if(!Character.isSpaceChar(d)){
System.out.print(c);
if(Character.isSpaceChar(d)){
if(!Character.isLetter(c)){
System.out.print(c);
}
if(Character.isLetter(c)){
System.out.print(Character.toUpperCase(c));
}
}
}
}
}
}
} 展开
public class Capitalize{
public static void main(String args[]){
String str;
char c,d;
Scanner keyboard=new Scanner(System.in);
System.out.println("This program is compiled by GaoQinghong.");
System.out.print("Enter a string -> ");
str= keyboard.next();
System.out.println("After compitalize:");
for(int i=0;i<str.length();i++){
c=str.charAt(i);
if(i==0)
{
if(Character.isLetter(c)){
System.out.print( Character.toUpperCase(c));
}
if(!Character.isLetter(c))
System.out.print(c);
}
if(i!=0){
d=str.charAt(i-1);
if(!Character.isSpaceChar(d)){
System.out.print(c);
if(Character.isSpaceChar(d)){
if(!Character.isLetter(c)){
System.out.print(c);
}
if(Character.isLetter(c)){
System.out.print(Character.toUpperCase(c));
}
}
}
}
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询