当前位置:网站首页>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 
边栏推荐
- Dialog+: Audio dialogue enhancement technology based on deep learning
- Programmer weekly (issue 4): the wealth view of programmers
- 2022-2028 global co extrusion production line industry research and trend analysis report
- 2022-2028 global horizontal reciprocating compressor industry research and trend analysis report
- Relinearization in homomorphic encryption (ckks)
- GStreamer initialization and plugin registry procedures
- ES6-- 集合
- Unity technical manual - life cycle rotation rotationoverlifetime- speed rotation rotationbyspeed- and external forces
- Yyds dry goods inventory JD 2, why is redis so fast?
- NRM source switching tool
猜你喜欢

ES6 --- 数值扩展、对象拓展

What is 5g? What can 5g do? What will 5g bring in the future?

OSPF - detailed explanation of GRE tunnel (including configuration command)

如何用jmeter做接口测试

Facing the "industry, University and research" gap in AI talent training, how can shengteng AI enrich the black land of industrial talents?

Tiger DAO VC产品正式上线,Seektiger生态的有力补充

Eureka core ⼼ source code analysis

简单好用的缓存库 gcache

The Ping class of unity uses

Why absolute positioning overlaps
随机推荐
Use of local stack in flask
ES6学习-- LET
[eosio] eos/wax signature error is_ Canonical (c): signature is not canonical
Openwrt (VIII) application layer development
APP-新功能上线
2022-2028 global iridium electrode industry research and trend analysis report
记|一次exists关键字的学习记录
Relinearization in homomorphic encryption (ckks)
[intensive lecture] 2022 PHP intermediate and advanced interview questions (II)
Civil Aviation Administration: by 2025, China will initially build a safe, intelligent, efficient and green aviation logistics system
Programmer weekly (issue 4): the wealth view of programmers
How to use the find command
2022-2028 global variable frequency compressor technology industry research and trend analysis report
2022-2028 global proton exchange membrane hydrogen electrolyzer industry survey and trend analysis report
Yyds dry goods inventory CEPH installation visual dashboard
Analysis report on market business model and development direction of China mobile operation industry from 2022 to 2028
Unity技术手册 - GetKey和GetAxis和GetButton
Privatization lightweight continuous integration deployment scheme -- 03 deployment of Web services (Part 2)
[dynamic programming] longest palindrome substring thinking about dynamic transfer cycle sequence
哪些PHP开源作品值得关注