Solved

wordsCount challenge

Posted on 2016-08-28
10
86 Views
Last Modified: 2016-08-30
Hi,

I wrote as below and passing all tests
public int wordsCount(String[] words, int len) {
int count=0;
for(int i=0;i<words.length;i++){
  if(words[i].length()==len){
    count++;
    
  }
  
  
}
return count;
  
}

Open in new window


any improvement to this?
0
Comment
Question by:gudii9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 41774403
>> any improvement to this?
Yes.
1) Give us the url of the challenge
2) Correctly indent your code
0
 
LVL 36

Assisted Solution

by:mccarl
mccarl earned 125 total points
ID: 41774404
You didn't link to the problem but I can pretty much deduce the requirements from the code. I wouldn't have done anything different to what you have done.
0
 
LVL 32

Accepted Solution

by:
awking00 earned 250 total points
ID: 41774657
Only a slight modification to what you have done -
int count = 0;
for (String word : words) {
  if (word.length == len) {
    count++;
  }
}
return count;
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 37

Expert Comment

by:zzynx
ID: 41774670
@awking00
That's a modification. But is it an improvement?
Also, only advisable when gudii9 is working with Java 8
0
 
LVL 32

Expert Comment

by:awking00
ID: 41774679
It wasn't meant as an improvement. I was only trying to show gudii9 an alternate means of looping through an array other than incrementing an index.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 41774707
It wasn't meant as an improvement.
It's good that that is cleared out now. Since he asked for improvements.

Correction: my remark about Java 8 is incorrect.
0
 
LVL 7

Author Comment

by:gudii9
ID: 41775287
for (String word : words) {
i like above.
0
 
LVL 7

Author Comment

by:gudii9
ID: 41775288
for each loop right?
0
 
LVL 7

Author Comment

by:gudii9
ID: 41775294
oops here is the URL of the problem.
http://codingbat.com/prob/p124620
 How to indent codingbat code without starting eclipse which some times takes time?

I used

http://codebeautify.org/javaviewer

it gave exact output after beautifying
beautify.png
0
 
LVL 37

Assisted Solution

by:zzynx
zzynx earned 125 total points
ID: 41775853
for each loop right?
Right

I used
http://codebeautify.org/javaviewer
it gave exact output after beautifying
That gives you an indentation of 1 space. Which is better than nothing.
But that's not what you posted.

How to indent codingbat code without starting eclipse which some times takes time?
By indenting by hand (= adding 4 spaces). It's so worth the effort. You gain readability for yourself and us.

Concerning your real question: there's nothing to improve.
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question