Function to check palindrome


Monday, November 13, 2023 Difficulty: Intermediate

Objective

Create a Java program that implements a function called isPalindrome() to check whether a string is a palindrome or not. A palindrome is a string that reads the same forwards and backward, like the word radar.

Instructions

  1. From the main function (main) of the program, prompt the user to enter a text string.
  2. Implement the isPalindrome() function that takes the entered string as a parameter and checks if it is a palindrome.
  3. The isPalindrome() function should return true if the string is a palindrome and false if it is not.
  4. Print on the screen a message indicating whether the string is a palindrome or not.

Input

radar

Output

true

Solution

Click here to view the exercise solution

Share it

Share it on your social media and challenge your friends to solve programming problems. Together, we can learn and grow.

Copied

The code has been successfully copied to the clipboard.

More Exercises

Continue improving your Java programming skills with our selection of practical exercises from the lesson. Click on Practice and challenge your knowledge!

1

Function greeting and farewell

Develop your Java skills by creating a program with greeting and farewell functions. Learn to execute methods effectively from the main function (Main).

2

Greet and bid farewell with parameters

Create a Java program that implements two methods for greeting and saying goodbye. The greeting method should have a text parameter.

3

Check alphabetical string

Create a Java program that implements a function called 'isAlphabetic()' which takes a text parameter from the user and checks if the text contains alphabetic characters from 'a' to 'z', including both uppercase and lowercase.

4

Replace character in a string

Explore text manipulation in Java with this intermediate-level exercise. Implement the changeLetter() function to modify a character in a text. Learn practically and enhance your mastery in programming!

5

Function sum

Create a Java program that implements a function called "sum" that returns the sum of two integer numbers passed as parameters.

6

Check numeric string

Create a Java program that implements a function called IsNumber that receives a text parameter from the user and check if the text is a number or not.

7

Calculator with command-line parameters

Create a Java program that serves as a calculator with the ability to add, subtract, multiply, or divide.

8

Function count spaces of a text

Create a program in Java that implements a function called CountSpaces that receives as a parameter a text requested from the user.

9

Function to sum the digits of a number

Create a Java program that asks the user for a number and save it in a text string.

10

Return value from Main

Create a new version of the program Main parameter calculator where you can return the following error codes from Main.

11

Find the minimum and maximum in an array

Create a Java program that implements a function called FindMinMax that receives three parameters, an array of real numbers and two real numbers.

12

Function to write format text

Create a program in Java that implements a function called WriteCenteredUnderline that receives as a parameter a text requested from the user.

13

Function to add an array of integers

Create a Java program that asks the user for 5 integers to store them in an array of integers.

14

Function to show an inverted string

Create a Java program that implements a function called InvertString receive receive a text by parameter and display them in reverse order.

15

Calculate double a number

Create a Java program that implements a function called Double to calculate and return double an integer.

16

Function to check palindrome

Create a Java program that implements a function to check if a string is a palindrome or not.

17

Search the greatest value in an array

Create a program in Java that implements a function called SearchGreatestValue that receives as an parameter an array of 5 real numbers requested from the user.

18

Function to calculate the power of a number

Create a Java program that implements a function called Power and calculate the result of raising an integer to another number.

19

Function to write text with title format

Create a Java program that implements a function called WriteTitle that writes a text centered on the screen, in capital letters, with additional spaces and with one line above and another below.

Functions

Practice with exercises in Java that use functions of different types. Methods, functions with parameters or values by reference among others.

Practice exercises

Keep learning

C# Programming Course

Free programming course with practical exercises and solutions in C#. Start learning right now!

Exercises C# App

Take your Exercises C# lessons everywhere with our Android app. Download it now from Google Play