[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

countEvens challenge

Posted on 2016-08-01
2
Medium Priority
?
145 Views
Last Modified: 2016-08-02
Hi,

I am working on below challenge

http://codingbat.com/prob/p162010
I wrote my code as below

public int countEvens(int[] nums) {
  int count=0;
  for(int n:nums){
    if(n%2==0){
      count++;
    }
  }
  return count;
  
}

Open in new window


I am passing all tests

How to improve my design, approach, code? please advise
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
2 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 2000 total points
ID: 41738279
You can't improve it
0
 
LVL 16

Expert Comment

by:gurpsbassi
ID: 41738973
Its a shame coding bat doesn't support java 8.
You could have done a one liner something like:

return IntStream.of(nums).filter( i -> i%2 == 0).count();
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
A solution for Fortify Path Manipulation.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses

650 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