Solved

Do the numbers thing in java

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ArrayIndexOutOfBoundException 9 67
starter POM and spring-boot-starter,  spring-boot-web 2 43
replace a word with other 1 40
Configure a Bean in an XML file 4 6
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
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 …

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now