• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

count of thw word

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My program getting sentence from users with Joptionpane.It getting as String. And program convert this String to Char Array. (sentence=sntn.toCharArray()) Sentence is a Array. And i want to find element of the Sentence Array so i use an other function (same class) Sentence[i] character. But the function dont find the Sentence[i] element. How can i fixed?
 
Hobi Kod
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hobi Kod wrote:My program getting sentence from users with Joptionpane.It getting as String. And program convert this String to Char Array. (sentence=sntn.toCharArray()) Sentence is a Array. And i want to find element of the Sentence Array so i use an other function (same class) Sentence[i] character. But the function dont find the Sentence[i] element. How can i fixed?



 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please tell us the full details. What goes wrong? Does the program compile? Does it throw Exceptions?

What is ks? Why is it there at all? You sho‍uld always start off a for loop like this:-
for (int i = 0; i < myArray.length; i++) ...
Now there is no need for ks. You may need to change that loop later, but you shou‍ld always think of that as the basic form of the for loop. I think you would do better to use a for‑each loop, however.
If you find 4 spaces, how many words do you have?
Have you come across a String method to create a String[]? Try it with "\\s+" as its argument. That is a regular expression for any number (> 0) of whitespace characters.

Don't use _ in variable names. Use mixedCaseWriting. Using _ except for constants is incorrect Java® style.
 
Hobi Kod
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have three function and an other function include this function. But second function does not work i dont understand.
i have thiss erorr mesage.

 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hobi Kod wrote:. . . i have thiss erorr mesage.

. . .

No, that is only part of the error message. Please show us the whole message, especially the first line, which will have an Exception name in.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hobi Kod wrote:And program convert this String to Char Array. (sentence=sntn.toCharArray())...


Why? Were you told to?

And what if your user types in:
  The   quick brown  fox      jumps over the   lazy dog
(ie, more than one space between words)

As Campbell has hinted, there are much better ways to get "words" from a String.

HIH

Winston
 
reply
    Bookmark Topic Watch Topic
  • New Topic