Word Counter in Java

Language
Here is a Java program I made in Java that counts the number of words and number of lines in of an inputted String. Check this out!
  1. import java.util.Scanner;
  2.  
  3. public class PrintPerWord
  4. {
  5.     public static void main(String[] args)
  6.     {
  7.         Scanner read = new Scanner(System.in);
  8.  
  9.         String myString = new String();
  10.  
  11.         System.out.print("Please enter any string: ");
  12.         myString = read.nextLine();
  13.         int line = 0, let = 0, size = 0;
  14.  
  15.         System.out.println("\nThe words are:");
  16.  
  17.         for(int i=0;i < myString.length(); i++)
  18.         {
  19.             char letter = myString.charAt(i);
  20.  
  21.             boolean ch = Character.isWhitespace(letter);
  22.  
  23.             if(ch || myString.length()-1==i)
  24.             {
  25.                 System.out.print(letter);
  26.                 System.out.println();
  27.                 let++;
  28.                 line++;
  29.                
  30.             }
  31.             else
  32.             {
  33.                 System.out.print(letter);
  34.             }
  35.         }
  36.         System.out.println("\nLines: " + line);
  37.         System.out.println("How many words: " + let);
  38.     }
  39. }

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Comments

can u make exam for dictionary thank you that is my assignment i need it so much!

Add new comment