Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: how to solve

1. ## how to solve

An array is initialized with n integers. Write a java program to locate all zeros in this array and shift them to the
left. The order of other numbers should not change in the array. e.g. Input: n = 10 6,10,0,89,678,8,0,64,0,3,0
Output: 0,0,0,0,610,89,678,8,64,3

3. ## Re: how to solve

Originally Posted by onlydeb
Write a java program to locate all zeros in this array and shift them to the left.
Are you allowed to use a secondary (temporary) array? But apart this, there are several possibile solutions to this exercise, ranging from the most trivials (and not-so-smart) to others more "smart".

4. ## Re: how to solve

Did your instructor give any hints? Are you allowed to ask other programmer's for techniques to solve the problem? A big part of programming is finding an algorithm for solving a problem. If part of your assignment is to find a solution, then our giving you an algorithm won't be fair to other students that work it out for themselves. Writing code for a given algorithm can be half of what is required to solve a problem.