• We just launched and are currently in beta. Join us as we build and grow the community.

Word Counter in Java

RetroNipplz

Micro-Influencer Manager
R Rep
0
0
0
Rep
0
R Vouches
0
0
0
Vouches
0
Posts
46
Likes
96
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 600 XP
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. public

    class

    PrintPerWord
  3. {
  4. public

    static

    void

    main(

    String

    [

    ]

    args)
  5. {
  6. Scanner read =

    new

    Scanner(

    System

    .in

    )

    ;

  7. String

    myString =

    new

    String

    (

    )

    ;

  8. System

    .out

    .print

    (

    "Please enter any string: "

    )

    ;
  9. myString =

    read.nextLine

    (

    )

    ;
  10. int

    line =

    0

    , let =

    0

    , size =

    0

    ;

  11. System

    .out

    .println

    (

    "\n

    The words are:"

    )

    ;

  12. for

    (

    int

    i=

    0

    ;

    i <

    myString.length

    (

    )

    ;

    i++

    )
  13. {
  14. char

    letter =

    myString.charAt

    (

    i)

    ;

  15. boolean

    ch =

    Character

    .isWhitespace

    (

    letter)

    ;

  16. if

    (

    ch ||

    myString.length

    (

    )

    -

    1

    ==

    i)
  17. {
  18. System

    .out

    .print

    (

    letter)

    ;
  19. System

    .out

    .println

    (

    )

    ;
  20. let++;
  21. line++;

  22. }
  23. else
  24. {
  25. System

    .out

    .print

    (

    letter)

    ;
  26. }
  27. }
  28. System

    .out

    .println

    (

    "\n

    Lines: "

    +

    line)

    ;
  29. System

    .out

    .println

    (

    "How many words: "

    +

    let)

    ;
  30. }
  31. }

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.


Download
You must upgrade your account or reply in the thread to view hidden text.
 

452,292

323,341

323,350

Top