// A method for finding the longest and shortest string
//and a method to split each word so i can see if it is a
// palindrome or not thanks for the help
{
public static void main(String[] args)
{
String string ;
int index ;
String sentence;
String newSentence;
String word;
int startPos;
int spacePos;
int wordCount;
boolean lastWord;
boolean alphaWord;
char letter;
System.out.println("Enter a string");
sentence = EasyIn.getString();
startPos = 0;
wordCount = 0;
lastWord = false;
newSentence = "";
do
{
spacePos = sentence.indexOf(" ", startPos);
if (spacePos == -1)
{
lastWord = true;
word = sentence.substring(startPos);
}
else
{
lastWord = false;
word = sentence.substring(startPos, spacePos);
}
index = 0;
alphaWord = true;
while ((index <= word.length()-1) && (alphaWord == true))
{
letter = word.charAt(index);
if ((letter >= 'a' && letter <= 'z') || (letter >= 'A' && letter <= 'Z'))
index++;
else
alphaWord = false;
}
if (alphaWord == true)
{
newSentence = newSentence + word + " ";
}
startPos = spacePos + 1;
} while (lastWord != true)
System.out.println();
for(index = newSentence.length()-1 ;index >= 0 ; index--)
{
System.out.print(" "+ newSentence.charAt(index) );
}
}
}
RavetodaGrave 0 Newbie Poster
verruckt24 438 Posting Shark
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.