当前位置:网站首页>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());
}
}
边栏推荐
猜你喜欢

Bridging the gap between open source databases and database services

SAP 脚本教程:SE71、SE78、SCC1、VF03、SO10-013

Trust level of discover

SAP ABAP 中的 Smart Forms-014

Process address space

【单片机】【让蜂鸣器发声】认识蜂鸣器,让蜂鸣器发出你想要的声音

Dear students, don't read the textbooks any more. Just read this one for the complexity of time

Uni develops wechat applet to customize automatic camera detection (portrait + ID card)

SAP web service 无法使用 SOAMANAGER 登陆到SOA管理页面

畅享高性能计算!天翼云HPC解决方案来了
随机推荐
GD32F4xx MCU 驱动mcp2515扩展CAN接口
How to open a futures account? Is it safe to open an online futures account?
SAP 脚本教程:SE71、SE78、SCC1、VF03、SO10-013
Mysql触发器
音视频基础知识|ANS 噪声抑制原理解析
数睿数据深度 | 关于软件自主可控,源代码向左,无代码向右
Trust level of discover
微信小程序头像挂件制作
84. (cesium chapter) movement of cesium model on terrain
4.字符串(倒序且大小写转换)
天翼云乘风新基建,构建数字化转型“4+2”能力体系
Make the text template in pycharm project support jinjia2 syntax
[Shanda conference] software performance optimization and bug repair
Be an we media video blogger, and share the necessary 32 material websites
知识管理在业务中的价值如何体现
数睿数据受邀参与南通企业数字化转型研讨会
Swift -- save print log to sandbox
odoo系统对原有模型单独开发的视图设置优先级
Pymssql Module User Guide
High precision calculation