每个单词间一个空格,首字母大写
2016-11-07 13:53
369 查看
//First,change the words to the standard form,where every word is separated by only one blank //Second,change every word's first alphabet to the upper import java.util.*; import java.lang.*; class Deal{ String deleteBlank(String words){ int flag=0; words=words.trim(); StringTokenizer temp = new StringTokenizer(words," "); String result=new String(""); while(temp.hasMoreTokens()){ if(flag==1) result+=" "; result+=temp.nextToken(); flag=1; } return result; } String changeFirstAlphabet(String words){ int in=0; char array[]=words.toCharArray(); for(int i=0;i<array.length;i++){ if(array[i]!=' '){ if(in==0&&Character.isLowerCase(array[i])) array[i]=Character.toUpperCase(array[i]); in=1; } else in=0; } String result=new String(array); return result; } } class FirstAlphabetUpper{ public static void main(String []args){ String words;; Scanner reader = new Scanner(System.in); Deal deal = new Deal(); words=reader.nextLine(); words=deal.deleteBlank(words); words=deal.changeFirstAlphabet(words); System.out.println(words); } }
相关文章推荐
- 使用JavaScript 将字符串中由空格隔开的每个单词首字母大写,写出通用方法。
- 将字符串中由空格隔开的每个单词首字母大写
- mysql 实现split函数功能,实现把由空格分割的词组每个单词的首字母转换成大写的功能
- 给出一句英文句子: "let there be light" 得到一个新的字符串,每个单词的首字母都转换为大写
- 将字符串中由空格隔开的每个单词首字母大写
- 编程在一个已知的字符串中查找最长单词,假定字符串中只含字母和空格,用空格来分隔单词。
- 编程在一个已知的字符串中查找最长单词,假定字符串中只含字母和空格,用空格来分隔单词。
- 串的处理 在实际的开发工作中,对字符串的处理是最常见的编程任务。本题目即是要求程序对用户输入的串进行处理。具体规则如下: 1. 把每个单词的首字母变为大写。 2. 把数字与字母之间用下划线字符(_)分
- SQL函数:将表中字段的每个单词首字母转化为大写
- 编程在一个已知的字符串中查找最长单词,假定字符串中只含字母和空格,用空格来分隔单词。
- 将字符串中的每个单词顺序进行颠倒,单词还是原来的单词,字母顺序不发生变化,将字符串中的空格用 代替
- 将一段英语的每个单词首字母大写
- 有一行字符,统计其中的单词个数(单词之间以空格分隔),并将每一个单词的第一个字母改为大写。
- 编程在一个已知的字符串中查找最长单词,假定字符串中只含字母和空格,用空格来分隔单词。
- 编程在一个已知的字符串中查找最长单词,假定字符串中只含字母和空格,用空格来分隔单词(只使用循环,数组)
- 编程在一个已知的字符串中查找最长单词,假定字符串中只含字母和空格,用空格来分隔单词。
- 让字符串中每个单词的首字母大写
- php:ucwords() --将字符串中每个单词的首字母转换为大写
- PHP 大小写转换、首字母大写、每个单词首字母大写转换相关函数
- 让每个单词的第一个字母自动大写