反转一个字符串
1.倒序输出
2.转换为Stringbuffer调用revers方法
3.存入字符数组,首尾调换
import java.util.Scanner;
public class Revers {
public static void main(String[] args) {
System.out.println("请输入字符串:");
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
char [] c=new char[s.length()];
for(int i=0;i<s.length();i++){
c[i]=s.charAt(i);
}
for(int i=s.length()-1;i>=0;i--){ //反向输出
System.out.print(c[i]);
}
System.out.println();
System.out.println("-------------");
for(int i=0;i<s.length()>>1;i++){ //首尾对换
char temp =c[i];
c[i]=c[s.length()-1-i];
c[s.length()-1-i]=temp;
}
for(int i=0;i<s.length();i++){
System.out.print(c[i]);
}
System.out.println();
System.out.println("------------");
StringBuffer sb=new StringBuffer(s); //转化为Stringbuffer调用函数 再转回string
sb.reverse();
sb.toString();
System.out.println(sb);
}
}
推荐阅读:
vue.js:634 [Vue warn]: Property or method "userName" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See:
SpringBoot 整合 webapp时 访问404的解决办法
SpringCloud怎么调用多个服务的信息
状态码:415,发送HTTP请求返回415状态码的解决办法
Vue 打开页面时就加载方法,例如查询
Spring整合Mybatis
SpringCloud 加入 thymleaf前端页面的方法
Controller之间的跳转
Spring AOP的实现原理
This may be the result of an unspecified view, due to default view name generation
行动消除疑虑