编辑代码

public class Main {
    public static boolean isPalindrome(String str) {
        int i = 0;
        int j = str.length() - 1;
        
        while (i < j) {
            if (str.charAt(i) != str.charAt(j)) {
                return false;
            }
            
            i++;
            j--;
        }
        
        return true;
    }
    
    public static void main(String[] args) {
        String str = "level";
        System.out.println(isPalindrome(str)); // 输出true
        
        str = "hello";
        System.out.println(isPalindrome(str)); // 输出false
    }
}