package com.itheima;
import java.util.Scanner;
public class Test3 {
/**第三题
* 判断一个字符串是否是对称字符串
* 例如"abc"不是对称字符串,"aba"、"abba"、"aaa"、"mnanm"是对称字符串
* @param args
*/
//用于跳出循环的标志
private static boolean isrun=true;
//
private static boolean issymmetry;
//主函数
public static void main(String[] args) {
//循环接收并处理输入的字符
while(isrun)
{
issymmetry = true;
//初始化接收键盘输入的scanner变量
Scanner userInput = new Scanner(System.in);
String input = userInput.nextLine();
int inputLength = (int)(input.length()/2);
System.out.println("inputLength:" + inputLength);
int i = 0;
while(inputLength != i)
{
System.out.println("i:" + i);
if(input.substring(i, (i + 1)).equals(input.substring((input.length() - i-1), (input.length() - i))))
{
System.out.println("第" + (i+1) + "个字符相对称于第" + (input.length()-i) + "个");
}
else
{
issymmetry = false;
System.out.println(input + "不是对称字符串");
break;
}
i ++;
}
if(issymmetry)
{
System.out.println(input + "是对称字符串");
}
}
}
}
|