当前位置:网站首页>4. string (reverse order and case conversion)
4. string (reverse order and case conversion)
2022-06-22 16:18:00 【Xiaomurong】
4 character string
Write a program , Realize the conversion of string case and output in reverse order . Requirements are as follows :
(1) Use for Loop the string “HelloWorld” Start traversing from the last character .
(2) If the current character traversed is an uppercase character , Just use toLowerCase() Method to convert it to lowercase characters , Otherwise use toUpperCase() Method to convert it to uppercase characters .
(3) Define a StringBuilder object , call append() Method to add the traversal characters in turn , Last call StringBuider Object's toString() Method , And output the obtained results .
public class Main {
public static void main(String[] args) {
String str = "HellowWorld";
StringBuffer sb = new StringBuffer();
char[] ch = str.toCharArray();
for (int i = str.length() - 1; i >= 0; i--) {
if (ch[i] >= 'a' && ch[i] <= 'z') {
sb.append(String.valueOf(ch[i]).toUpperCase());// Law 1
}
if (ch[i] >= 'A' && ch[i] <= 'Z') {
sb.append(str.toLowerCase().toCharArray()[i]);// Law two
}
}
System.out.print(sb.toString());
}
}
边栏推荐
猜你喜欢
![[single chip microcomputer] [make buzzer sound] know the buzzer and let it make the sound you want](/img/cb/826b3591bafa62cc71826732eb32ef.png)
[single chip microcomputer] [make buzzer sound] know the buzzer and let it make the sound you want
![[Shanda conference] application setting module](/img/1e/1665234715b365614a753355274ced.png)
[Shanda conference] application setting module

知识管理在业务中的价值如何体现

让pycharm项目里面的文本模板支持jinjia2语法

Alibaba cloud middleware's open source past

畅享高性能计算!天翼云HPC解决方案来了

Discover the number of media new users can insert

odoo本地文档功能开发记录

#进程地址空间

Research on ICT: domestic databases focus on the ICT market, and Huawei Gauss is expected to become the strongest
随机推荐
[译文] 弥合开源数据库和数据库业务之间的鸿沟
[Huawei cloud to Jian Zhiyuan] the winning list of essay solicitation is released!
[Shangshui Shuo series] day three - VIDEO
【山大会议】一些基本工具类定义
[Shanda conference] private chat channel webrtc tools
GD32F4xx MCU 驱动mcp2515扩展CAN接口
5.文件的读写(学生类)
SAP ABAP 中的模块化:宏、子程序和功能模块 -04
SAP ABAP 内部表:创建、读取、填充、复制和删除-06
十九、Xv6上下文切换(上下文切换的实现;状态机的封装与恢复)
校企联合在路上!华为云GaussDB又来高校啦
SAP ABAP 中的 Smart Forms-014
Mysql触发器
Applet development - Custom expiration cache
Gbase "library" special training of innovation and application Committee of Beijing fintech Industry Alliance
Quick sort_ sort
odoo本地文档功能开发记录
C语言贪吃蛇
知识管理在业务中的价值如何体现
phantomJs使用总结