Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a new project Lab06b, and write a program that determines if the given te

ID: 3634057 • Letter: C

Question

Create a new project Lab06b, and write a program that determines if the given text is palindrome. A palindrome is a word, phrase, number, or other sequence of units that can be read the same way in either direction. In this project, you can assume the input will only consist of characters. Write a static method that takes the text as a parameter and returns true if the text is palindrome, returns false otherwise. Write another static method in order to print whether the text is palindrome or not. This static method should take a boolean value as a parameter and print the result accordingly should not return anything.


Below are example outputs from the program:

Enter a string: Step on no pets
Text is palindrome!

Enter a string: A nut for a jar of Tuna
Text is palindrome!

Enter a string: noon
Text is palindrome!

Enter a string: Lon Nola
Text is not palindrome!

Explanation / Answer

Dear,

As you didnot give any programming language,
we do assume it is java.

//importing packages
import java.util.Scanner;
import java.util.*;
//class Palindrome
class PalindromeTest
{

public static void main(String[] args)
{
//name of type string
String name;
//create an object of type Scanner to read string from keyboard
Scanner in=new Scanner(System.in);
System.out.print("Enter a string:");
//read a line
name=in.nextLine();
//passing name as argument to isPalindrome static method
boolean flag=isPalindrome(name);
//passing the boolean value to print method whether to print the given
//string palindrome or not
print(flag);
}
//print static method
public static void print(boolean flag)
{
if(flag==true)
System.out.println("Text is palindrome..!");
else
System.out.println("Text not is palindrome..!");
}
//ispalindrome static method
public static boolean isPalindrome(String name)
{
int len=name.length();
String temp;
int count=0;
//convert to upper case
name=name.toUpperCase();
//reverse the sting
temp=new StringBuffer(name).reverse().toString();
//compare two strings
if(name.compareTo(temp)==0)
return true;
else
return false;
}
}

Hope this would helpful to you..

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote