当前位置:网站首页>String deformation (string case switching and realization)
String deformation (string case switching and realization)
2022-06-25 23:01:00 【if you never leave me, i will be with you till death do us apart】
Supplement basic knowledge :
JAVA in String Class provides methods for converting to uppercase toUpperCase() And the method of converting to lowercase toLowerCase()
String a = "ABC";
system.out.println(a.toLowerCase());//abc
String b = "abc";
system.out.println(b.toUpperCase());//ABC
Exercise description :
describe
For a length of n character string , We need to deform it .
First of all, the string contains some spaces , It's like "Hello World" equally , Then what we need to do is reverse order the words separated by spaces in this string , Invert the case of each character at the same time .
such as "Hello World" After deformation, it becomes "wORLD hELLO".
Code :
package com.example.test;
import java.util.Scanner;
public class test {
public static void main(String[] args) {
System.out.println(" Please enter the fields you want to reverse ");
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
String st = scanner.nextLine();
int len = st.length();
System.out.println(" The length is " + len);
String ll= tanstring(st, len);
System.out.println(" The converted value is "+ll);
}
}
private static String tanstring(String st, int se) {
String res = "";
String tempStr = "";
for (int i = 0; i < se; i++) {
char c = st.charAt(i);//i For the length st Enter content for charAr Similar to getting subscripts
if (c >= 'a' && c <= 'z') {
tempStr += Character.toUpperCase(c); //java Method body Convert upper case to lower case
} else if (c >= 'A' && c <= 'Z') {
tempStr += Character.toLowerCase(c); //java Method body Lower case to upper case
}
// hither The above method completes the case switching Separate each word Size switch
// Here's how Sequential switching
// String splicing After each cycle tempStr The values of are obtained last The last value obtained is spliced in the front You can achieve sequential switching
else {
tempStr = c + tempStr;
// Save the value of the last cycle
res = tempStr + res;
tempStr = "";
}
}
res = tempStr + res;
System.out.println(" The output data is " + res);
return res;
}
}
The result is
Please enter the fields you want to reverse
Hello Word Yan
The length is 14
The output data is yAN wORD hELLO
Here is a debug Of Pictures are better understood Letter exchange 
边栏推荐
- 记|一次exists关键字的学习记录
- Unity的Ping类使用
- [eosio] eos/wax signature error is_ Canonical (c): signature is not canonical
- ES6学习-- LET
- Intimacy - [comfortable exit] - final communication to reduce injury
- Obsidian basic tutorial
- 2022-2028 global co extrusion production line industry research and trend analysis report
- Interview shock 23: talk about thread life cycle and transformation process?
- 目前期货怎么开户安全些?哪些期货公司靠谱些?
- Simple and easy-to-use cache library gcache
猜你喜欢

腾讯《和平精英》新版本将至:新增账号安全保护系统,游戏内违规行为检测升级

Canoe: the fifth simulation project: simulation + test

Tiger Dao VC products are officially launched, a powerful supplement to seektiger ecology

Use apiccloud AVM multi terminal component to quickly realize the search function in the app

Programmer weekly (issue 4): the wealth view of programmers

2022 love analysis · panoramic report of it operation and maintenance manufacturers

小程序绘制一个简单的饼图

再突破!阿里云进入Gartner云AI开发者服务挑战者象限

2022-2028 global industrial touch screen industry research and trend analysis report

Glory launched the points mall to support the exchange of various glory products
随机推荐
Simple and easy-to-use cache library gcache
QT learning setting executable exe attribute (solving the problem of Chinese attribute garbled)
Relinearization in homomorphic encryption (ckks)
提问的智慧?如何提问?
华为云SRE确定性运维专刊(第一期)
Dio encapsulé pour les requêtes réseau flutter (gestion des cookies, ajout d'intercepteurs, téléchargement de fichiers, gestion des exceptions, annulation des requêtes, etc.)
Nacos 源码分析01 代码结构
2022-2028 global DC linear variable differential transformer (LVDT) industry survey and trend analysis report
ES7/ES9 -- 新特性与正则
你好,请问老师,在支付宝基金开户真的安全吗?
2022年河南省第一届职业技能大赛网络安全项目试题
What are the channels for Internet advertising to gain customers?
Use apiccloud AVM multi terminal component to quickly realize the search function in the app
ADB common commands
Trillions of hot money smashed into the space economy. Is it really a good business?
数据治理,说起来容易,做起来难
[dynamic programming] longest palindrome substring thinking about dynamic transfer cycle sequence
Unity技术手册 - 粒子基础主模块属性-上
How to disable the optical drive
2022 love analysis · panoramic report of it operation and maintenance manufacturers