I have a Code,
import java.util.*;
import java.util.Scanner;
import java.util.StringTokenizer;
class CountWords{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
System.out.print("Enter string: ");
String st=input.nextLine();
int count=0;
StringTokenizer stk=new StringTokenizer(st," ");
while(stk.hasMoreTokens()){
String token=stk.nextToken();
count++;
}
System.out.println("Number of words are: "+count);
}
}
I hava a requirement that given a input as string like "This Is the!@* text to did() madam#$ split in to words."
o/p:-
Number of words are: 10
and
I have to count the no. of words of the string by neglecting the special characters of the string and store into a table column and also store the reverse of the word in another table column like(ignoring special characters in the string)
sno words reverse
---- ------ --------
1 This sihT
2 Is sI
3 the eht
4 text text
so.... on and if there are palindromes in the string,then kept that words in separate table like
word palindrome
---- ---------
did did
madam madam
Thanks in advance