1328: 整理书籍

题目

Description

马克得到了很多书,但是给他的书目清单名字的格式比较混乱,没有注意大小写。现要请你帮马克整理成统一规范的格式,即书籍名的第一个字符是字母要大写,其他字母小写。
如将The Secret Garden转换成The secret garden。
Input

多组输入,每行一个单词,长度不超过30,表示马克手中的书籍名。书籍名由字母、数字、空格和-组成。
Output

n行,每行一个单词,对应输入的书籍名的规范写法。
Sample Input

The Secret Garden
A Tale of Two Cities
Anna Karenina
A Tale of Two Cities
Sample Output

The secret garden
A tale of two cities
Anna karenina
A tale of two cities


代码块


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner cn = new Scanner(System.in);
        String str;
        while(cn.hasNext()){
            str = cn.nextLine();
            str = str.toLowerCase();
            char[] ch = str.toCharArray();
            if(ch[0]>='a'&&ch[0]<='z')
            ch[0] = (char) (ch[0]-32);
            System.out.println(ch);
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值