Solved

Do the numbers thing in java

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
splitOdd10 challenge 5 105
Java - Why doesn't this JFrame work 3 58
table example 4 29
mysql jsp example issue 32 32
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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 third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

785 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