Results 1 to 4 of 4
  1. #1
    Happypanda is offline Member
    Join Date
    Jun 2012
    Posts
    7
    Rep Power
    0

    Default Help with finding how many words there are in a sentence.

    Java Code:
    import java.util.Scanner;
    
    public class JFindAlphabet
    {
    	static Scanner sc = new Scanner(System.in);
    
    	public static void main(String[] Me)
    	{
    
            System.out.println("Enter a string:");
            String Armadillo = sc.nextLine();
    
            int VowelCount = 0,ConsonantCount = 0,WordCount = 0,SpaceCount = 0,SpecialCharCount = 0;
    
            for (int Bat = 0; Bat < Armadillo.length(); Bat++)
            {
    			char Cat = Armadillo.charAt(Bat);
    			if (      (Cat == 'A') || (Cat == 'a')
    			       || (Cat == 'E') || (Cat == 'e')
    			       || (Cat == 'I') || (Cat == 'i')
    			       || (Cat == 'O') || (Cat == 'o')
    			       || (Cat == 'U') || (Cat == 'u') )
    			VowelCount++;
    
    			char Dog = Armadillo.charAt(Bat);
    			if (      (Dog == 'B') || (Dog == 'b')
    			       || (Dog == 'C') || (Dog == 'c')
    			       || (Dog == 'D') || (Dog == 'd')
    			       || (Dog == 'F') || (Dog == 'f')
    			       || (Dog == 'G') || (Dog == 'g')
    			       || (Dog == 'H') || (Dog == 'h')
    				   || (Dog == 'J') || (Dog == 'j')
    				   || (Dog == 'K') || (Dog == 'k')
    			       || (Dog == 'L') || (Dog == 'l')
    			       || (Dog == 'M') || (Dog == 'm')
    				   || (Dog == 'N') || (Dog == 'n')
    				   || (Dog == 'P') || (Dog == 'p')
    				   || (Dog == 'Q') || (Dog == 'q')
    				   || (Dog == 'R') || (Dog == 'r')
    				   || (Dog == 'S') || (Dog == 's')
    				   || (Dog == 'T') || (Dog == 't')
    			       || (Dog == 'V') || (Dog == 'v')
    				   || (Dog == 'W') || (Dog == 'w')
    				   || (Dog == 'X') || (Dog == 'x')
    				   || (Dog == 'Y') || (Dog == 'y')
    				   || (Dog == 'Z') || (Dog == 'z') )
                ConsonantCount++;
    
    			char Alpaca = Armadillo.charAt(Bat);
    						if (      (Alpaca == ' ')  )
    			SpaceCount++;
    
    			char Tiger = Armadillo.charAt(Bat);
    						if (      (Tiger == '`') || (Tiger == '~')
    						       || (Tiger == '1') || (Tiger == '!')
    						       || (Tiger == '2') || (Tiger == '@')
    						       || (Tiger == '3') || (Tiger == '#')
    						       || (Tiger == '4') || (Tiger == '$')
    						       || (Tiger == '5') || (Tiger == '%')
    							   || (Tiger == '6') || (Tiger == '^')
    							   || (Tiger == '7') || (Tiger == '&')
    						       || (Tiger == '8') || (Tiger == '*')
    						       || (Tiger == '9') || (Tiger == '(')
    							   || (Tiger == '0') || (Tiger == ')')
    							   || (Tiger == '-') || (Tiger == '_')
    							   || (Tiger == '=') || (Tiger == '+')
    							   || (Tiger == '[') || (Tiger == '{')
    							   || (Tiger == ']') || (Tiger == '}')
    							   || (Tiger == ';') || (Tiger == ':')
    						       || (Tiger == ',') || (Tiger == '<')
    							   || (Tiger == '.') || (Tiger == '>')
    							   || (Tiger == '/') || (Tiger == '?') )
    
    			SpecialCharCount++;
    
    			char Lion = Armadillo.charAt(Bat);
    			           if (      (Lion == Armadillo.substring(" "," ")) || (Lion == Armadillo.substring(" ",".")) )
    			           WordCount++;
    		}
    		System.out.println("There are " + VowelCount + " vowels in this sentence"                   );
    		System.out.println("There are " + ConsonantCount + " consonants in this sentence"           );
    		System.out.println("There are "  + SpaceCount + " spaces int this sentence"                 );
            System.out.println("There are " + SpecialCharCount + " special characters in this sentence.");
        }
    }
    This my current code I can't figure out how to make my program identify words. Can someone help me?
    Last edited by Happypanda; 07-08-2012 at 11:14 PM.

  2. #2
    Happypanda is offline Member
    Join Date
    Jun 2012
    Posts
    7
    Rep Power
    0

    Default Re: Help with finding how many words there are in a sentence.

    Bump

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Help with finding how many words there are in a sentence.

    This question is being cross-posted and multi-posted several places. Lord help me jebus.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Random sentence generator
    By BrAD19924 in forum New To Java
    Replies: 6
    Last Post: 05-03-2011, 03:58 AM
  2. Finding words (and more) in another file
    By Lund01 in forum Java Applets
    Replies: 5
    Last Post: 09-30-2010, 02:03 PM
  3. Finding out number of Palindromes in a Sentence
    By rameshiit19 in forum New To Java
    Replies: 1
    Last Post: 09-13-2010, 04:44 AM
  4. Finding a word in a sentence?
    By blackrabbit in forum New To Java
    Replies: 6
    Last Post: 07-23-2010, 12:07 AM
  5. Replies: 0
    Last Post: 02-25-2010, 01:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •