package com.work;
import java.util.Scanner;
public class Demo05 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请录入字符串");
String s = sc.next();//123321
//int count = 0;
boolean flag = true;//true代表对称,false代表不对称
for(int i = 0,j = s.length() - 1;i < s.length()/2;i++,j--) {
if(s.charAt(i) != s.charAt(j)) {
flag = false;
break;
}
}
if(flag) {
System.out.println(s + "是对称的");
} else {
System.out.println(s + "不是对称的");
}
/*if(count == (s.length()/2) ) {
System.out.println("是对称字符串");
}*/
}
}
需求:键盘接收一个字符串,程序判断出该字符串是否是对称字符串,并在控制台打印是或不是
最新推荐文章于 2023-10-14 22:28:21 发布