首字母大写

来源:互联网 发布:python 拆分字符 编辑:程序博客网 时间:2024/04/28 01:05

首字母大写

时间限制:
1000ms
内存限制:
65536kB
描述
对一个字符串中的所有单词,如果单词的首字母不是大写字母,则把单词的首字母变成大写字母。在字符串中,单词之间通过空白符分隔,空白符包括:空格(' ')、制表符('\t')、回车符('\r')、换行符('\n')。
输入
输入一行:待处理的字符串(长度小于80)。
输出
输出一行:转换后的字符串。
样例输入
if so, you already have a google account. you can sign in on the right.
样例输出
If So, You Already Have A Google Account. You Can Sign In On The Right.
import java.util.Scanner;public class Main{public static void main(String[] args){Scanner sc=new Scanner(System.in);String srt1=sc.nextLine();String[] str=srt1.split(" ");int n=str.length;for(int i=0;i<n;i++){int m=str[i].length();if(m>0){char ch=str[i].charAt(0);int p=(int)ch;if(p>=65&&p<=91){System.out.print((char)p);}else{if(p>=97&&p<=123){   System.out.print((char)(p-32));}else{System.out.print((char)p);}}for(int j=1;j<m;j++){char chh=str[i].charAt(j);System.out.print(chh);}}System.out.print(" ");}}}


原创粉丝点击