JAVA get positive numbers array java - Net-Raft.com

Welcome aboard! We are happy you are here and wish you good net-raft!




Just a Web Code Solution

get positive numbers in array java


 217

JAVA


1

public class test
{
public static void main(String[] args) {
int[] numbers = {6,-2,5,-4,1};
for(int n : getPositiveNumbers(numbers)){
System.out.print(n);
}


}
public static int[] getPositiveNumbers(int[] numbers)
{
int count = 0;
for (int n : numbers)
{
if(n>0)
{
count++;
}
}
int [] nums = new int[count];
int i =0;
for (int n : numbers)
{
if(n>0)
{
nums[i] = n;
i++;
}
}

return nums;

}
}


By     Created   
The power of the user (%)
60%



The most helpful JAVA solutions

how to get the minimum value from array using java ?how to get the minimum value from array using java ?JAVA

Click to see more ...

  605     49

how to create lower case using java ?how to create lower case using java ?JAVA

Click to see more ...

  516     41

get userdomain using java get userdomain using java JAVA

Click to see more ...

  334     37

how to get the values from an array using java ?how to get the values from an array using java ?JAVA

Click to see more ...

  228     32

how to create the replace function of special characters using java ?how to create the replace function of special characters using java ?JAVA

Click to see more ...

  130     31

how to get the second value from an array using java ?how to get the second value from an array using java ?JAVA

Click to see more ...

  108     19

how to create upper case using java ?how to create upper case using java ?JAVA

Click to see more ...

  81     17

How to read a key on the keyboard using java ?How to read a key on the keyboard using java ?JAVA

Click to see more ...

  62     16

how to get the maximum value from array using java ?how to get the maximum value from array using java ?JAVA

Click to see more ...

  56     13

how to create replace function using java ?how to create replace function using java ?JAVA

Click to see more ...

  42     12