Array-promo

Question

print largest palindrome words in given sentence.

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram

Code

				
					
import java.util.Scanner;
public class largestPalindromeWordsInSentence 
{  
    public static void main(String[] args)
    {  
        String sen="",wd="",wd1="",largestPalindrome="";
        char ch=' ',ch1=' ';
        int i=0,len=0;
        Scanner sc = new Scanner(System.in);    
        
        System.out.println("Enter a sentence");   
        sen = sc.nextLine(); 
        sen=sen+" ";
        sen=sen.toLowerCase();
        len=sen.length();

        for(i=0;i< len;i++)
        {
            ch=sen.charAt(i);
            if(ch==' ')
            {
                
                if(wd.equals(wd1)==true)
                {
                    if(wd.length()>largestPalindrome.length())
                    {
                        largestPalindrome=wd;
                    }
                }
                wd1="";
                wd="";
                
            }
            else
            {
                wd=wd+ch;
                wd1=ch+wd1;
            }
        }
                System.out.println("Largest Palindrome words in sentence:"+largestPalindrome);   

    }  
}    

				
			

Coding Store

Leave a Reply

Your email address will not be published. Required fields are marked *