package com.harvard.cs60;

import java.util.Scanner;

public class Palindrome {

public static void main(String[] args) {

System.out.println(“Enter a string to check if it is a palindrome:”);

Scanner scanner = new Scanner(System.in);

String inputString = scanner.nextLine();

if (isPalindrome(inputString)) {

System.out.println(“The input String is a palindrome.”);

} else {

System.out.println(“The input String is not a palindrome.”);

}

}

public static boolean isPalindrome(String inputString) {

int length = inputString.length(); // find the length of the input string int i, begin, end, middle; // declare that you are going to use these variables in the following code

begin = 0; // start at the beginning of the string, index 0

end = length – 1; // set end to be just before the end of the string by doing length – 1 (0 based counting)

middle = (begin +

import java.util.*;

import java.util.Scanner;

public class PalindromeChecker {

public static void main(String[] args) {

System.out.println(“Enter a string to check if it is a palindrome: “);

Scanner scanner = new Scanner(System.in);

String inputString = scanner.nextLine();

String reverse = reverseString(inputString);

// Checking whether the string is palindrome or not

if (inputString.equals(reverse)) {

System.out.println(“The input string is a palindrome.”);

} else {

System.out.println(“The input string is not a palindrome.”);

}

}

// Method to reverse any string

public static String reverseString(String input) {

char[] inp = input.toCharArray();

for (int i = 0; i < inp.length / 2; i++) { char temp = inp[i]; inp[i] = inp[inp.length - 1 - i]; in public class Palindrome { public static void main(String[] args) { String str, rev = ""; Scanner in = new Scanner(System.in); System.out.println("Enter a string to check if it is a palindrome"); str = in.nextLine(); int length = str.length(); for ( int i = length - 1; i >= 0; i– )

rev = rev + str.charAt(i);

if (str.equals(rev))

System.out.println(“Entered string is a palindrome.”);

else

System.out.println(“Entered string is not a palindrome.”);

} }

The following program is a program that determines if a word is a palindrome. It is important to be able to identify a palindrome to avoid grammatical errors in writing.

The word “palindrome” was coined from Greek roots palin (πάλιν; “again”) and dromos (δρóμος; “way, direction”), by English writer Ben Jonson in the 17th century. The word “palindrome” first appeared in English in the late 16th century and has been used primarily as an adjective. A common example of a palindrome is the word racecar, which reads the same forward or backward, although backwards it spells racecar.

The following program uses a while loop and an array to determine if a word is a palindrome. It shows how efficient arrays are because they are able to store information without having to use variables for each character of the string.

public class Palindrome {

public static void main(String [] args) {

for (int i = 0; i < args.length; i++) { String s = args[i]; System.out.println(s + " is palindrome? " + isPalindrome(s)); } } public static boolean isPalindrome(String s) { if (s == null || s.length() <= 1) return true; if (s.charAt(0) != s.charAt(s.length()-1)) return false; return isPalindrome(s.substring(1, s.length() - 1)); } } //Palindrome.java import java.util.*; import java.io.*; public class Palindrome { public static void main(String[] args) throws Exception { //for time test: long start = System.currentTimeMillis(); BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); ArrayList palindromes = new ArrayList();

for (;;) { //loop forever…or until the user enters an empty line.

System.out.print(“Please enter a word or phrase (enter blank line to quit): “);

String line = input.readLine().trim(); //get rid of leading and trailing whitespace on the line

if (line.equals(“”)) break; //if they entered a blank line, exit the loop

String s = getLetters(line).toLowerCase();

if (isPalindrome(s)) {

palindromes.add(“\”” + line + “\” IS a palindrome”);

} else {

palindromes.add(“\”

import java.util.Scanner;

public class Palindrome {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

System.out.print(“Input a word:”);

String str = in.nextLine();

System.out.println(“The word ‘” + str + “‘ is a palindrome: ” + isPalindrome(str));

}

public static boolean isPalindrome(String s) {

if (s == null || s.isEmpty()) {

return true;

}

int i = 0, j = s.length() – 1;

while (i < j) { if (s.charAt(i) != s.charAt(j)) { return false; } i++; j--; } return true; } }

Tomy

Tomy is a contributor at AskMeCode. We are committed to providing well-researched, accurate, and valuable content to our readers.

You May Also Like

4 Ways To Convert An Integer to a Short

4 Ways To Convert An Integer to a Short

public class Factorial { public static void main(String[] args) { // TODO code application logic here int number = 5;...

what are the most common coding interview questions? Here you go

what are the most common coding interview questions? Here you go

The time has come to share the top 50 most common coding interview questions asked in interviews. These questions have...

OpenAI Codex program is open to anyone

OpenAI Codex program is open to anyone

OpenAI Codex is a program to train AI agents in the world's most popular games, starting with Dota 2 and...

Artistic representation for Coding Best Practices on a Budget: Money-Saving Tips

Coding Best Practices on a Budget: Money-Saving Tips

The Environmental Impact of Software Development Software development isn’t just about writing code—it’s also about understanding the broader consequences of...

Leave a Reply

About | Contact | Privacy Policy | Terms of Service | Disclaimer | Cookie Policy
© 2026 AskMeCode. All rights reserved.