answersLogoWhite

0

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.util.Vector; /**

*

*/ /**

* @author omnipath

*

*/

public class Palindrome { /**

* @param args

*/

public static void main(String[] args) { // open up standard input

BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String string = null; // readLine() method try { string = br.readLine(); } catch (IOException ioe) { System.out.println("IO error trying to read input!"); System.exit(1); }

Palindrome palindromeCase = new Palindrome(string);

System.out.println("The longest palindrome is: " + palindromeCase.palindrome);

System.out.println("The length of the longest palindrome is: " + palindromeCase.palindrome.length());

System.out.println("Counter is: " + palindromeCase.PalindromeCounter);

} String originalString;

String palindrome;

Vector vectPalindromes;

int palindromeLength;

int PalindromeCounter; public Palindrome(String s) {

PalindromeCounter = 0;

this.palindrome = "";

this.palindromeLength = this.palindrome.length();

this.originalString = s;

this.calculateLongestPalindrome(s);

} public void calculateLongestPalindrome(String s) {

if (s.length() == 1) {

this.palindrome = this.originalString;

this.palindromeLength = this.palindrome.length();

} this.parseForPalindrome(this.originalString); } public void parseForPalindrome(String s) {

PalindromeCounter++;

if (s.length() -1; i--) {

sb.append(s.charAt(i));

}

return sb.toString();

}

}

User Avatar

Wiki User

15y ago

Still curious? Ask our experts.

Chat with our AI personalities

FranFran
I've made my fair share of mistakes, and if I can help you avoid a few, I'd sure like to try.
Chat with Fran
CoachCoach
Success isn't just about winning—it's about vision, patience, and playing the long game.
Chat with Coach
RafaRafa
There's no fun in playing it safe. Why not try something a little unhinged?
Chat with Rafa

Add your answer:

Earn +20 pts
Q: Largest palindrome substring of a string?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

The substring method returns?

"[Substr] returns a string object with its contents initialized to a substring of the current object."


What is substr function does in c?

it will give the substring of length(as per the user) from the actual string,and the starting length from where it has to copy the substring from actual should be given by the user.


How do you use sub string in java?

Substring method creates smaller string form bigger string , every time a new string is created but original character array buffer is used. so even if original string is 1G in size and substring is just 1K memory held by substring is 1G because of backed array. this can cause memory leak and prevent original string from garbage collection even if there is no direct reference.


Program to check that given string is palindrome or not in C?

/*To check whether a string is palindrome*/includeincludevoid main () { int i,j,f=0; char a[10]; clrscr (); gets(a); for (i=0;a[i]!='\0';i++) { } i--; for (j=0;a[j]!='\0';j++,i--) { if (a[i]!=a[j]) f=1; } if (f==0) printf("string is palindrome"); else printf("string is not palindrome"); getch (); }


Bluej program-read a string and check if the given string is a palindrome?

import java.util.Scanner; public class Palindrome{ public static void main(String[] args){ String front; String back =""; char[] failure; String backwards; Scanner input=new Scanner(System.in); System.out.print("Enter a word: "); front=input.next(); front=front.replaceAll(" ", ""); failure=front.toCharArray(); for (int i=0; i<failure.length; i++){ back=failure[i] + back; } if (front.equals(back)){ System.out.print("That word is a palindrome"); }else System.out.print("That word is not a palindrome"); }}