Hbu|2-35 判断回文字符串

【Hbu|2-35 判断回文字符串】用两个指针就好了~

import java.util.Scanner; public class test6 { public static void main(String[] args) { Scanner s = new Scanner(System.in); String str = s.nextLine(); String q = ""; boolean flag = true; for(int i = 0, j = str.length() -1; i <= j; ){//双指针 if(str.charAt(i) == str.charAt(j)){ i ++; j --; } else{ flag = false; break; } } if(flag) System.out.println("yes"); else System.out.println("no"); } }


    推荐阅读