// need help with this how do i get the for loop to print out just
//the alphabetic words

{
	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();
		
		for(index = sentence.length()-1 ;index >= 0 ; index--)
		{
		System.out.print(" "+  sentence.charAt(index) );
		}

		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 + " ";
					wordCount++;
				}
		
			

			startPos = spacePos + 1;
		
		} while (lastWord != true);
		
		System.out.println();
		System.out.println(newSentence);
		System.out.println("The number of alphabetic words is: " + wordCount);
		
	}
	
	
}

I'm kind off missing a question in your post.

Use regex to check whether a string is made up of alphanumeric characters or only letters then print out the ones you need.

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.