当前位置:网站首页>字符串反转方法总结
字符串反转方法总结
2022-06-09 08:25:00 【源氏不可挡】
1.利用StringBuilder的reverse方法
import java.util.*;
import java.io.*;
public class Main{
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str=br.readLine();
StringBuilder sbtr=new StringBuilder(str);
sbtr.reverse();
System.out.println(sbtr.toString());
}
}
2.利用栈的先进后出
public class Main{
public static void main(String[] args) {
Stack stack = new Stack();
Scanner in = new Scanner(System.in);
String s = in.nextLine();
for (int i = 0; i <s.trim().length() ; i++) {
stack.push(s.charAt(i));
}
while(!stack.empty()){
System.out.print(stack.pop());
}
}
}
3.倒序遍历字符串
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s = in.nextLine();
for (int i = s.length()-1; i >=0 ; i--) {
System.out.print(s.charAt(i));
}
}
}
边栏推荐
- GC学习笔记
- [pat (basic level) practice] - [sort] 1077 mutual evaluation score calculation
- IELTS review 1
- js类的创建和constructor的构造函数的使用
- mysql中if和ifnull
- 2022-2028 investigation and trend analysis report on global anti UAV netting gun industry
- RMAN备份概念_关于RMAN备份的多个拷贝
- 搞明白 left join、right join和join的区别
- [paper introduction] clip: image and natural language pairing pre training transferable visual models from natural language supervision
- 【天线】【2】一些名词和简单概念的解释,仍然
猜你喜欢
![[introduction to the paper] 2204 Vqgan-clip (open source):open domain image generation and editing with natural language guidance](/img/4b/009d09dd775cad943274ac7e825948.png)
[introduction to the paper] 2204 Vqgan-clip (open source):open domain image generation and editing with natural language guidance

Blow up the idea artifact in use recently

通过低代码和无代码实现保险行业客户体验突破

No, you still can't read the log with requestid?

阿里云ack免密拉取企业版acr镜像

苹果胜诉 法官驳回iPhone安全欺诈集体诉讼

OpenInfra Summit 2022 | 安超云用户脱颖而出 入围超级用户大奖

leetcodeSQL:1070. Product sales analysis III
![[paper introduction] clip: image and natural language pairing pre training transferable visual models from natural language supervision](/img/31/4b728c8f719d19fad798c0b55f4221.png)
[paper introduction] clip: image and natural language pairing pre training transferable visual models from natural language supervision

【读点论文】Benchmark Analysis of Representative Deep Neural Network Architectures当准确率不再是唯一衡量标准,给多目标优化一个导向
随机推荐
EDA开源仿真工具verilator入门1:安装和测试
配置RMAN备份的环境_配置通道(Channel)
Alibaba cloud ack pull free enterprise ACR image
Nacos 启动报错[db-load-error]load jdbc.properties error
C language review 9
剖析虚幻渲染体系(15)- XR专题
GC学习笔记
配置RMAN备份的环境_配置控制文件和服务器参数文件的自动备份
自制编译器学习2:编译的过程
About Matrix Decompositions
【读点论文】EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks网络结构要像身材一样匀称且体量和处理能力匹配
小米官网移动端布局
Implementation of WTM based on NETCORE framework
RMAN备份概念_关于RMAN控制文件和服务器参数文件的自动备份
国信证券开户安全吗
Market Research - current situation and future development trend of global and Chinese floating fish feed market
84.1%受访家长感到身边喜欢用电子产品哄孩子的家长多
RedLock红锁安全性争论(上)
Excerpt of a verse of compassion and gladness
C language review 12