帮忙写个java的练习题代码,万分感谢!!!
发布网友
发布时间:2022-05-06 12:40
我来回答
共1个回答
热心网友
时间:2022-06-30 14:01
public class myTest
{
public static void main(String[] args)
{
String[] strArr = { "010", "3223", "666", "7890987", "123123" };
System.out.println(getSymmetricString(strArr));
}
public static String getSymmetricString(String[] strArr)
{
String allInfo = "";
int sum = 0;
for (String str : strArr)
{
boolean flag = true;
for (int i = 0; i < str.length() / 2; i++)
{
String bgnStr = str.substring(i, i + 1);
String endStr = str.substring(str.length() - (i + 1), str.length() - i);
if (!bgnStr.equals(endStr))
{
flag = false;
break;
}
}
if (flag)
{
allInfo = allInfo + str + "是对称的,对称的数量为:" + str.length() / 2 + "\n";
sum++;
}
else
{
allInfo = allInfo + str + "不是对称的" + "\n";
}
}
return allInfo + "\n对称字符的个数为:" + sum;
}
}