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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: how to solve

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,105
    Thanks
    48
    Thanked 2,153 Times in 2,126 Posts

    Default Re: how to solve

    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: how to solve

    Quote Originally Posted by onlydeb View Post
    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".
    Andrea, www.andbin.netSCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginnersMy new project Java Examples on Google Code

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,105
    Thanks
    48
    Thanked 2,153 Times in 2,126 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. How to solve??
    By Mumpy Zinu in forum What's Wrong With My Code?
    Replies: 0
    Last Post: November 2nd, 2013, 10:51 AM
  2. How to solve this?
    By jellescheer in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 12th, 2012, 09:14 AM
  3. anyone can help me to solve this?
    By d3sm0nd in forum What's Wrong With My Code?
    Replies: 13
    Last Post: June 27th, 2012, 06:47 AM
  4. Solve Them Please
    By omath in forum Java Theory & Questions
    Replies: 1
    Last Post: December 25th, 2010, 03:26 PM