Solved

# Do the numbers thing in java

Posted on 2004-10-04
212 Views
Given a long array of integers that contains positive/negative numbers or zeros, write a function/method in Java that would move all negative numbers to the front of the array and all positive numbers to the end of the array, and return the index of the first positive integer
0
Question by:cplusplus030999
[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

LVL 92

Accepted Solution

objects earned 38 total points
ID: 12223018
Arrays.sort(intarray);

then loop thru the array looking for 1st +ve
0

LVL 21

Assisted Solution

MogalManic earned 37 total points
ID: 12225270
You need to break the problem down into steps
>Given a long array of integers that contains positive/negative numbers or zeros,
>write a function/method in Java that would move all  negative numbers to the
>front of the array and all positive numbers to the end of the array, and return
>the index of the first positive integer

You will need to iterate through the array and for each item in the array
1. Move all negative numbers to the front of the array
2. Move all positive numbers to the end of the array
2.5  If 1st positive Integer, save index
At the end
3. Return index of 1st positive integer

Keep adding detail until you have a program

0

Expert Comment

ID: 12234939
Sort your array and search the first number which is greater than zero and return its index.
0

## Featured Post

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
###### Suggested Courses
Course of the Month3 days, 6 hours left to enroll