1328: 整理书籍

xiaoxiao2021-02-27  180

题目

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); } } }
转载请注明原文地址: https://www.6miu.com/read-14390.html

最新回复(0)