![]() |
|
|
|
| ||||||
|
Welcome to the The ProgrammersTalk Community forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| Tags: |
![]() |
![]() | | LinkBack | Thread Tools | Display Modes | ![]() |
| |||
| [SOLVED] fix the error in java program...? import java.util.*; class Ch9CountWords { private static final char BLANK = ' '; public static void main (String[] args) { //Attempt No. 2 //There is still a problem with the Attempt No. 2 code. //If the sentence ends with one or more blank spaces, then the //value for wordCount will be one more than the actual number of //words in the sentence. It is left as an exercise to correct //this bug. int index, wordCount, numberOfCharacters; Scanner in = new Scanner(System.in); // when running next(), stop when ENTER is pressed in.useDelimiter("\n" This program has an error, when user enters more than two spaces after the sentence, the program counts words one too many. is there anyone that can fix this? |
| |
![]() |
| Thread Tools | |
| Display Modes | |
| |