Solved

Do the numbers thing in java

Posted on 2004-10-04
5
218 Views
Last Modified: 2010-03-31
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
Comment
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
  • Learn & ask questions
5 Comments
 
LVL 92

Accepted Solution

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

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

Assisted Solution

by:MogalManic
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

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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 …
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

628 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