数组-05. 字符串字母大小写转换(10)
来源:互联网 发布:服务网络 编辑:程序博客网 时间:2024/04/29 08:40
输入一个以#结束的字符串,本题要求将小写字母全部转换成大写字母,把大写字母全部转换成小写字母,其它字符不变。
输入格式:
输入在一行中给出一个长度不超过40的、以#结束的非空字符串。
输出格式:
在一行中按照要求输出转换后的字符串。
输入样例:Hello World! 123#输出样例:
hELLO wORLD! 123
import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner cin = new Scanner(System.in);String str = cin.nextLine();StringBuffer sb = new StringBuffer();for (int i = 0; i < str.length(); i++) {if (str.charAt(i) == '#') {break;}if (str.charAt(i) >= 'a' && str.charAt(i) <= 'z') {sb.append((char) (str.charAt(i) + 'A' - 'a'));} else if (str.charAt(i) >= 'A' && str.charAt(i) <= 'Z') {sb.append((char) (str.charAt(i) + 'a' - 'A'));} else {sb.append(str.charAt(i));}}System.out.print(sb);}}
0 0
- 数组-05. 字符串字母大小写转换(10)
- 数组-05. 字符串字母大小写转换(10)
- 数组-05. 字符串字母大小写转换(10)
- 数组-05. 字符串字母大小写转换(10)
- 数组-05. 字符串字母大小写转换(10)
- 数组-05. 字符串字母大小写转换(10)
- 字符串字母大小写转换(10)
- 字符串字母大小写转换
- 6-2. 字符串字母大小写转换(10)
- 6-2. 字符串字母大小写转换(10)
- 6-2. 字符串字母大小写转换(10)
- 6-2. 字符串字母大小写转换(10)
- 06-2. 字符串字母大小写转换(10)
- 06-2. 字符串字母大小写转换(10)
- 06-2. 字符串字母大小写转换(10)
- 06-2. 字符串字母大小写转换(10)
- 06-2. 字符串字母大小写转换(10)
- 06-2. 字符串字母大小写转换(10)
- MATLAB中的光照处理
- 聚合、组合、关联的区别
- vc中调用dll传参数
- 2014辽宁省省赛 luckly number
- OCP 1Z0 053 15
- 数组-05. 字符串字母大小写转换(10)
- 1004 成绩排名
- 任意两个日期的差值
- Android学习心得(一)
- 多次调用同一个过程效率下降的问题
- 设计模式之中介者模式(Mediator)摘录
- (c=getchar())!=EOF
- python Decorator装饰器用法二
- 判断数是否可以被整除(大数)