题目:判断一个字符串是否是对称字符串,例如"abc"不是对称字符串,"aba"、"abba"、"aaa"、"mnanm"是对称字符串
- import java.util.Scanner;
- public class Demo01 {
- public static void main(String[] args) {
- boolean is = true;
- Scanner sc = new Scanner(System.in);
- while(true){
- String str = sc.next();
- char[] ch = str.toCharArray();
- int j = str.length();
- for(int i = 0 ; i < str.length(); i++){
- if(ch[i] != ch[j-i-1]){
- is = false;
- }
- }
- if(is == false){
- System.out.println("不是对称的!!!");
- }else{
- System.out.println("是对称的~~~~~~~");
- }
- }
- }
- }
复制代码
实现:多次输入并判断是否为对称字符串,请问,不经过编译运行找是否错误,若有错误,如何解决? |
|