aiaiask.com©

开花即结果 提问即答案

2023蓝桥杯javaB组试题
原始问题:

2023蓝桥杯javaB组试题

1、实现一个函数,判断输入的字符串是否是回文(回文就是一个正读和反读都一样的字符串)

public static boolean isPalindrome(String str) {

if (str == null || str.length() == 0) { 
    return false; 
} 

int start = 0; 
int end = str.length() - 1; 

while (start < end) { 
    if (str.charAt(start) != str.charAt(end)) { 
        return false;   // 发现不相同则返回false  

    } else {   // 相同则比较前后一对字符  

        start++;   // 移动比较指针  

        end--;     // 移动比较指针  

    }     

}     

return true;     // 全部相同,返回true。      

}

2023蓝桥杯javaB组试题
https://www.aiaiask.com/ask/6639.html
AI / 模型Siliconflow
时间 / DATEApril 5, 2023, 5:07 PM
语言zh-CN
IP / 区域辽宁 铁岭