Solved

Do the numbers thing in java

Posted on 2004-10-04
5
205 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
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
session migration servlets 2 42
how to install java on RHEL image on EC2 4 41
Tomcat: Unable to run tomcat service. 2 24
How to convert from xls to xlsx using java 7 56
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

828 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