Copy array and sort the numbers in the new array

Hi!
I have an array containing some digits where some of the digits are zeros. I want to copy the digits to another array but the zeros (well, I actually want to copy the zeros as well but I want to have them in the end of the new array).
I suppose I need an if-statement that checks if the old array contains any zeros and in that if-statement copy the content to the new array and put the zeros in the end.
This is my code so far and I don�t know how to go on from here:
int[] new_array = new int[array.length];
          for (int i = 0; i < array.length; i++)
               if (array[i] > 0)
                    new_array[i] = array;
                    new_array = array;
               System.out.print(new_array[i] + " ");

Roxxor wrote:
I think I know how to do it but only if I can catch the digits bigger than zero.
My code below just checks if there are positive digits and if there are, the whole old array is copied to the new one.Yes. Don't do that, you can see it's wrong.
So my problem is that I don�t know how to catch the digits bigger than zero and copy them. Is there any built in java keyword that catches signs, number etc?
if (array>=0)
     new_array[i] = array[i];
     new_array = array;
Yes, there is such a keyword. And you are already using it correctly in your code. You are already testing if the array entry is bigger than zero. Your only problem is, you don't know what to do when it is. But now you've been given two hints about what to do.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • How to increment an element in an array and put it back in the same array?

    I have an array of values generated by another part of my program. My goal is to count the number of occurences for each integer value in the array and put these values in a new array. This new array will be a histogram of the input array. My approach is to do auto-indexing with a for loop. In the loop I use a "index array" to get the current value of the histogram array and a "replace array subset" to update the array element with "current+1". The problem is that when I wire the output of the "replace array subset" VI back to its input, I get a wire error. I guess I cannot wire it like that, but what should I do? Is there a completely different approach to do this that
    is more elegant?
    Thanks for your help!
    Benoit

    Hi Benoit,
    I believe the thing that's missing is a shift register.
    Right-click on the edge of your "For loop" and select add shift register.
    Wire an initialized array to the shift register left terminal before entering the "for loop". Wire from this same terminal (inside the loop) as the source of the info used in your "index array" and replace array. The results of these two operations (just the way you are doing it now) gets wired to the "right terminal" of the shift register (inside the loop).
    What ever you stuff into the right terminal, gets returned via the left terminal on the next iteration of the loop. When the loop is done, your final array of counts can be accessed by wiring from the "right terminal" (outside the loop).
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • I'm using Big date theme but the numbers on the date is cut off on top.  I'm on iphoto 11 and OS 10.8.2.  anyone else having this issue??

    I'm using Big date theme but the numbers on the date is cut off on top.  I'm on iphoto 11 and OS 10.8.2.  anyone else having this issue??

    OK try the following: make a temporary, backup copy (if you don't already have a backup copy) of the library and try the following:
    1 - delete the iPhoto preference file, com.apple.iPhoto.plist, that resides in your
         User/Home/Library/ Preferences folder.
    2 - delete iPhoto's cache file, Cache.db, that is located in your
    User/Home/Library/Caches/com.apple.iPhoto folder (Snow Leopard and Earlier).
    or with Mt. Lion from the User/Library/Containers/com.apple.iPhoto/
    Data/Library/Caches/com.apple.iPhoto folder
    3 - launch iPhoto and try again.
    NOTE: If you're moved your library from its default location in your Home/Pictures folder you will have to point iPhoto to its new location when you next open iPhoto by holding down the Option key when launching iPhoto.  You'll also have to reset the iPhoto's various preferences.
    NOTE 2:  In Lion and Mountain Lion the Library folder is now invisible. To make it permanently visible enter the following in the Terminal application window: chflags nohidden ~/Library and hit the Enter button - 10.7: Un-hide the User Library folder.

  • Copying the numbers from the calculator widget.

    Hello!
    Is it me, or it is impossible to copy the numbers from the calculator widget in 10.6.3?
    Thanks,
    Chris.

    It happened again! I don't understand!
    I did a test: I restarted the computer. I typed in the calculator. Copied, and pasted in Mail. Worked fine.
    After, I opened Illustrator CS3. Copied something from there, and pasted it in Flash. Worked fine.
    After, I went back to the calculator, copied the numbers, and when I pasted the numbers in Mail, it's Illustrator's graphics that pasted instead of the numbers.
    After, I went on the net, copied text from a site. Pasted it in Mail. Worked fine. Went back to the calculator, copied, and the pasted text was the text from the Website, and not from the calculator.
    This is very frustrating!
    Any idea on my problem?
    Thanks,
    Chris.

  • Main.vi creates 2D Arrays and I want to save the arrays in an microsoft Excel file(e.g engine_1)and in differnt worksheets(e.g. measure_1;measure_2;...)

    main.vi creates 2D Arrays and I want to save the arrays in an microsoft Excel file(e.g engine_1)and in differnt worksheets(e.g. measure_1;measure_2;...)
    The path(Grundpfad)for the excel file should be inserted in the main.vi.

    1. There's a shipping example called Write Table To XL.vi (Help>Find Examples>Communicating with External Applications>ActiveX>Excel) that you can use as a starting point.
    2. Buy the LabVIEW Report Generation Toolkit. Info can be found here.
    3. Search this forum for other examples of writing to Excel.

  • HT1343 if one is using windows 8.1 on a boot camped mac and you are using a mac keyboard . How does one unlock the numbers  on the larger wired keyboard ( numbers keys to the right of the keyboard) instead of having to use the numbers at the top of the ke

    Question: I am using a mac , wired Keyboard, on  a windows 8.1 platform ( this is because I have boot camped my hard drive) Unfortunately when I change over from my mac set up into the windows 8.1 the key board does not behave like it does when I am using as a mac. The numbers , on the right of the keyboard , no longer function and I have to use the numbers at the top of the keyboard, very annoying. Can anybody let me know how I unlock the numbers on the right of my keyboard?
    Regards CM

    I have stated every issue I’ve had so far in a fairly clear and concise way. I think if you read what I wrote, it all makes logical sense as to what is going on. Windows 7/8 would work just as well on a Mac if it was supported the same way the OS is for other OEMs.
    As I stated earlier in the post, I’m having these same issues in windows 8, not just 8.1, which is the reason for the post. I know the difference between supported by drivers and not supported by the manufacturer. The fact that when Haswell mbp’s came out and no revision to bootcamp for the new hardware was released to fix issues with installing windows on the new hardware shows Apple clearly Is not supporting bootcamp as strongly as they advertise.
    I am being realistic on Apple having drivers early. Anyone with an MSDN subscription can download the RELEASE version of windows months ahead of the actual release, I’m 100% sure if any average consumer can do that by paying $100 and saying they are a developer, apple can do it just as easily.
    You aren’t much help, you haven’t answered really anything to my post, nor have you contributed any knowledge that wasn’t clearly posted above, so don’t say anything if you don’t have anything to contribute.
    By the way, my rant is directed at apple, as you can see because I am saying “Apple, if you are going to…” because this is an Apple forum on Apple’s website. It is not directed to end users, clearly.

  • I have a itune gift card  and the numbers on the back  came off . i have the store receit  but the store can not help me

    i have i tune gift card and the numbers on the back are gone i have the store receit but thay can not help

    Try contacting Apple through their Express Lane.
    Just click iTunes on the left > iTunes Store > iTunes Cards and Codes, and then fill out the form to see if they can take care of the problem.

  • I keep putting in my passcode but my iPad won't show the numbers in the blocks and it won't open.  I have tried double tapping in the numbers

    I keep putting in my passcode but my iPad won't show the numbers in the blocks and consequently it won't open for me. I have tried double tapping in the numbers and then it shows the numbers in the blocks correctly but then it responds with a wrong code in red and then locks me out.
    Typing in the code takes a long time which might indicate a full HD.

    iOS: Device disabled after entering wrong passcode
    http://support.apple.com/kb/ht1212
    How can I unlock my iPad if I forgot the passcode?
    http://tinyurl.com/7ndy8tb
    How to Reset a Forgotten Password for an iOS Device
    http://www.wikihow.com/Reset-a-Forgotten-Password-for-an-iOS-Device
    Using iPhone/iPad Recovery Mode
    http://ipod.about.com/od/iphonetroubleshooting/a/Iphone-Recovery-Mode.htm
    Saw this solution on another post about an iPad in a school enviroment. Might work on your iPad so you won't lose everything.
    ~~~~~~~~~~~~~
    ‘iPad is disabled’ fix without resetting using iTunes
    Today I met my match with an iPad that had a passcode entered too many times, resulting in it displaying the message ‘iPad is disabled – Connect to iTunes’. This was a student iPad and since they use Notability for most of their work there was a chance that her files were not all backed up to the cloud. I really wanted to just re-activate the iPad instead of totally resetting it back to our default image.
    I reached out to my PLN on Twitter and had some help from a few people through retweets and a couple of clarification tweets. I love that so many are willing to help out so quickly. Through this I also learned that I look like Lt. Riker from Star Trek (thanks @FillineMachine).
    Through some trial and error (and a little sheer luck), I was able to reactivate the iPad without loosing any data. Note, this will only work on the computer it last synced with. Here’s how:
    1. Configurator is useless in reactivating a locked iPad. You will only be able to completely reformat the iPad using Configurator. If that’s ok with you, go for it – otherwise don’t waste your time trying to figure it out.
    2. Open iTunes with the iPad disconnected.
    3. Connect the iPad to the computer and wait for it to show up in the devices section in iTunes.
    4. Click on the iPad name when it appears and you will be given the option to restore a backup or setup as a new iPad (since it is locked).
    5. Click ‘Setup as new iPad’ and then click restore.
    6. The iPad will start backing up before it does the full restore and sync. CANCEL THE BACKUP IMMEDIATELY. You do this by clicking the small x in the status window in iTunes.
    7. When the backup cancels, it immediately starts syncing – cancel this as well using the same small x in the iTunes status window.
    8. The first stage in the restore process unlocks the iPad, you are basically just cancelling out the restore process as soon as it reactivates the iPad.
    If done correctly, you will experience no data loss and the result will be a reactivated iPad. I have now tried this with about 5 iPads that were locked identically by students and each time it worked like a charm.
    ~~~~~~~~~~~~~
    Try it and good luck. You have nothing more to lose if it doesn't work for you.
     Cheers, Tom

  • How can I create the numbering of the week in ICal

    I want to know how I can adjust ICal with the numbering of the week. I really need the number of the week often.
    Can somebody give my an answer, I looked for it and I can't find the option?
    Regards,

    Teduister,
    Welcome to Apple Discussions.
    According to Hawk Wings, you may want to consider: NumSemaine...NumSemaine is a little app which adds the week of the year to “All Day Event” Section of your iCal window.
    Not least, this drives home how soon Christmas will be upon us.
    It can also generate a ics file containing all the weeks of the year and their date ranges.
    ;~)

  • Have the developers considered randomizing the numbers for the passcode?  It is easy to watch the pattern when someone enters their passcode.  However, if the numbers appeared is a random order each time, it would enhance the security feature even more.

    Have the developers considered randomizing the numbers for the passcode?  It is easy to watch the pattern when someone enters their passcode.  However, if the numbers appeared is a random order each time, it would enhance the security feature even more.  Personally, I would prefer this option with security in mind.

    He slightly beat you Meg, and I'm in the same boat with you. If I used a passcode I believe I would go with the feature to use a longer alphanumeric passcode rather than a 4 digit number even with the random code entry.
    And of course if Apple did put this feature in they need to make it an option or we'll see lots of posts wanting to know how to get rid of it.

  • I'm only able to input the numbers of the redemption code not the letters. how to fix

    I'm only able to input the numbers of the redemption code not the letters. how to fix

    Are you sure you are using the Redemption code and not the serial number?  See if this page helps:
    <Find your serial number quickly>
    If it is really a redemption code then you need to redeem it for a proper serial number.  See if this helps:
    <Redemption Code Help>
    Good luck.

  • The numbering of the bank statements is not sequential

    Hi expert,
    When I load the bank statements in transaction FEBA, the numbering of the bank statements is not sequential.
    Eg: Error
    Statement No    Date                  Amount
    223                   10.01.2010        xxxx
    222                   10.01.2010        xxxx
    221                   10.01.2010        xxxx
    106                   01.02.2010        xxxx
    105                   01.02.2010        xxxx
    104                   01.02.2010        xxxx
    220                   10.01.2010        xxxx
    219                   10.01.2010        xxxx
    218                   10.01.2010        xxxx
    How can I make it sequential?
    Thank you.
    Kind regards,
    Sridhar Sha

    Please note the statement number is normally provided by your bank.
    I would contact your bank to ask why the numbering changed.
    There is normally a check inside SAP that looks at opening statement balance and statement number.
    Perhaps your coder have turned this off. - Please check with them over this.

  • Is there a way for my daughter or her friends to block their numbers from showing up on activities page. At first i could see them, as of yesterday i can no longer see the numbers in the activities page. But i do see that she has texted them when looking

    Is there a way for my daughter or her friends to block their numbers from showing up on activities page. At first i could see them, as of yesterday i can no longer see the numbers in the activities page. But i do see that she has texted them when looking at her phone.

    First of all, there is no need to put the entire text of your post into the title of your thread.
    Next, does your daughter have an iPhone? Do her friends have iPhones? If the answer to both questions is "yes", then it is possible she is not texting them, but using iMessage to communicate with them. iMessages will not show up in the texting traffic on a line as they are not texts, but messages sent thru Apple's servers.
    For all "texts" to show up in the texting activity of an iPhone, you must disable iMessage on the device. Any messages sent as iMessages(blue bubbles around the text) on an iPhone will not show up in any texting activity.

  • I´m trying to call a number for buying products on phone but the numbers occupied the hole time 0200 810329

    I´m trying to call a number for buying products on phone but the numbers occupied the hole time 0200 810329

    Please refer to:
    Adobe | Sales Inquiries
    Contact | Adobe
    Regards
    Rajshree

  • Hi I hav a 2010 Mercedes E350 an lost my iPhone. I nw have an I phone 4s my all my contacts are on the cars phone kit. Is there any way I can get the numbers from the phone kit onto my new iPhone.

    Hi I hav a 2010 Mercedes E350 an lost my iPhone. I nw have an I phone 4s all my contacts are on the cars phone kit. Is there any way I can get the numbers from the phone kit onto my new iPhone.

    If you were not syncing the contacts in your phone with a contact manager or cloud service, there is no way to get them from the car to the phone other than manually re-entering them in the phone.

Maybe you are looking for

  • Nokia Lumia 1520 upgraded to Windows Phone 8.1 G.D...

    Hello reader(S), Today I accepted the Fast Ring (which was the only offered ring) programme on my Nokia Lumia 1520 to install the latest preview builds of Windows 10 and provide feedback for Microsoft... but here's the odd part, it installed Windows

  • Authorization check for vendor bank details

    Hallo. Is it possible for certain users who have the authorization for creating vendor master data not to have access to their bank details? Thanks in advance.

  • Missing features in Symbian Anna (Is it only me? o...

    I installed the Symbian Anna Update which was released yesterday (18th August 2011) and got trough the update process despite the difficulties the Software Updater in my phone caused. After the update I noticed some features are missing: (Not Adobe r

  • Generics in SimpleListProperty and SimpleObjectProperty

    Hi everyone, My understanding of generics may be shakier than I thought, but I was under the impression that I should be able to have: public abstract class GenericContainer<E, P extends javafx.beans.property.Property<E>> {}And then subclass as:1. pu

  • How to use lenovorecovery cd with yoga 2 pro

    Hi everyone, I need to restore factory settings and Windows 8.1 after a format (i deleted even the restore partition) i did on my lenovo yoga 2 pro. I ordered the cd and I'm using an external dvd reader, but I can't seem to be able to boot from the c