Write a Java program to check if a string is a palindrome or not.

Sure, here’s a Java program to check if a string is a palindrome or not:

import java.util.Scanner;

public class PalindromeCheck {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter a string: ");
        String input = scanner.nextLine();

        boolean isPalindrome = checkPalindrome(input);
        if (isPalindrome) {
            System.out.println("The string is a palindrome.");
        } else {
            System.out.println("The string is not a palindrome.");
        }
    }

    public static boolean checkPalindrome(String str) {
        int left = 0;
        int right = str.length() - 1;
        while (left < right) {
            if (str.charAt(left) != str.charAt(right)) {
                return false;
            }
            left++;
            right--;
        }
        return true;
    }
}

In this program, we first prompt the user to enter a string using the `Scanner` class. Then, we call the `checkPalindrome()` method to check if the string is a palindrome or not.

The `checkPalindrome()` method uses two pointers, one starting from the beginning of the string and the other starting from the end of the string. It compares the characters at the two positions and moves the pointers towards each other until they meet in the middle of the string. If any of the characters do not match, the method returns `false`. If all the characters match, the method returns `true`.

Finally, we print whether the string is a palindrome or not to the console using the `println()` method.

Note that this program assumes that the string is case-sensitive, meaning that uppercase and lowercase characters are treated as different. To make the program case-insensitive, you can convert the input string to lowercase or uppercase using the `toLowerCase()` or `toUpperCase()` method before checking for palindromes.