当前位置:网站首页>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 
边栏推荐
- Unity technical manual - getKey and getaxis and getbutton
- 多模态数据也能进行MAE?伯克利&谷歌提出M3AE,在图像和文本数据上进行MAE!最优掩蔽率可达75%,显著高于BERT的15%...
- Hotspot JVM "01" class loading, linking and initialization
- 等价类,边界值,场景法的使用方法和运用场景
- 2022-2028 global SiC igniter industry research and trend analysis report
- ES7/ES9 -- 新特性与正则
- Unity技术手册 - 粒子基础主模块属性-上
- Obsidian basic tutorial
- c语言与数据库的创建使用
- 【EOSIO】EOS/WAX签名错误 is_canonical( c ): signature is not canonical 问题
猜你喜欢

简单好用的缓存库 gcache

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

What is 5g? What can 5g do? What will 5g bring in the future?
![Lecture 14 of the Blue Bridge Cup -- number theory [exercises]](/img/96/0971909c8bf25820c2d4f520bb83fb.jpg)
Lecture 14 of the Blue Bridge Cup -- number theory [exercises]
[invitation letter] on March 4, the platform enabled digital intelligence Innovation -- UFIDA BiP PAAS cloud platform IUAP digital intelligence hundred cities forum · Jinan Station

使用EAST ocr遇到的坑解决方法(编译lanms)

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

Chapter 3 use of requests Library

不荒唐的茶小程序-规则改动

Nacos 源码分析01 代码结构
随机推荐
Three layer architecture + routing experiment
Open source optimized VVC encoder in general scenarios
MySQL数据库常用函数和查询
Unity technical manual - color in life cycle coloroverlifetime-- speed color colorbyspeed
Another breakthrough! Alibaba cloud enters the Gartner cloud AI developer service Challenger quadrant
Oracle - 基本入门
一位博士在华为的22年
万亿热钱砸向太空经济,真的是一门好生意?
Intimacy - [comfortable exit] - final communication to reduce injury
ES7/ES9 -- 新特性与正则
简单好用的缓存库 gcache
华为云短信测了很多手机都提示发送频繁
How to open a futures account safely at present? Which futures companies are more reliable?
China coated abrasive tools industry market depth analysis and development strategy consulting report 2022-2028
Simple and easy-to-use cache library gcache
Why can't the mobile phone be used and the computer be connected
Lecture 14 of the Blue Bridge Cup -- number theory [example]
Unity technical manual - particle foundation main module attributes - upper
面对AI人才培养的“产学研”鸿沟,昇腾AI如何做厚产业人才黑土地?
不荒唐的茶小程序-规则改动