Hi everyone,

I'm just wondering in Java, if there was a way to just check once for a number in an array?

for (int i = 0; i < array.length; i++)
{
if (array[i]>0){
count++;
}
}

This code will check for all positive numbers. Is there a way to just check for the first positive number and ignore the rest?

Put a "break" in that if statement. Or use a "while" statement.

or
i = array.length (for another alternative)
but, masijade 's solutions are better

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.