Question
Frequency of Non-Palindrome words in given sentence using recursion
ENTER THE SENTENCE
MOM AND DAD ARE NOT AT HOME
FREQUENCY OF NON-PALINDROME WORDS IN GIVEN SENTENCE:5
Share code with your friends
Share on whatsapp
Share on facebook
Share on twitter
Share on telegram
Code
import java.util.Scanner;
public class FrequencyNonPalindromeWordsInSentence
{
public static String FindReverse(String wd,int i)
{
if(i>=0)
{
return wd.charAt(i)+ FindReverse(wd,i-1);
}
else
{
return "";
}
}
public static void main()
{
int i=0,count=0;
char ch=' ';
String sen="",word="";
Scanner sc=new Scanner(System.in);
System.out.println("ENTER THE SENTENCE");
sen=sc.nextLine();
sen=sen+" ";
for(i=0;i< sen.length();i++)
{
ch=sen.charAt(i);
if(ch==' ')
{
if(word.equals(FindReverse(word,word.length()-1))==false)
{
count++;
}
word="";
}
else
{
word=word+ch;
}
}
System.out.println("FREQUENCY OF NON-PALINDROME WORDS IN GIVEN SENTENCE:"+count);
}
}