Find unique numbers in an array.

How would I find unique numbers in an array by using only one array?

At the above codes, I use the String representation of the number that I want to find. I know that it is an easy example but it can give you an idea that how Hash works in Java.
Give symbols(aliases) to your numbers which helps you to remember the each specific number, so you can find specific number by only using its symbol(nickname) instead of using its location which is more difficult to remember.
import java.util.*;
* ...Hashdescription...
* @author  ...yourname...
* @version 1.00, 2006/05/19
public class Hash
     // properties
     ArrayList keys;
     ArrayList values;
     // constructors
     public Hash(){
          keys = new ArrayList();
          values = new ArrayList();
     // methods
     public void add(int val){
          values.add(new Integer( val));
          keys.add("" + val);
     public int get(String key){
          int index = keys.indexOf(key);
          return ((Integer)(values.get(index )) ). intValue();
     public static void main( String[] args)
          Hash list = new Hash();
          list.add(1);
          list.add(2);
          list.add(3);
          list.add(4);     
          list.add(5);
          list.add(6);
          list.add(7);
          list.add(8);
          list.add(9);
          System.out.println(list.get("3"));
} // end of class Hash

Similar Messages

  • Find missing numbers in array

    HI !
    I have an array which holds 999 different numbers between 1-1000
    (which means that 1 number between 1-1000 does not appear in the array).
    I need to find the missing number in one pass and it's easy.
    My question is:
    Do you have any idea how can I find 2 missing numbers in the array ?
    Is it possible ?
    I cant use any data structure and I need to find the missing numbers in one pass.
    Thank you

    Using array.sort() and using another array is out of the question as its inhrently banned in the "i cant use any data structure" so this is
    Homework! tut tut
    ok so far an array with 1 number missing "its easy" yeah, just add em all up and see whats missing.
    for 2 numbers missing you should take a hint from what you are studying in the course ie solving Quadratic Equations..
    shall i make snoopy beg yet??
    naw, ok here goes
    on your 1 permitted pass add up all the mumbers that are there, also have another total for the squares of the numbers
    call the numbers you are looking for A and B
    subtract the first total from what it would be if there were all 1000, call this N
    subtract the second total from what the total of the squares would be if there were all 1000, call this M
    so..
    A+B=N
    solve for B in terms of A
    so..
    B=N-A
    and A^2+B^2=M
    should i quit now???
    no, ok
    substitute B in the second equation, shuffle a bit and..
    2A^2-2NA+N^2-M=0
    recognise the terms of the quadratic and..
    A=(2N +/- (4N^2-8(N^2-M))^.5)/4
    note the +/- plus OR minus will give you 2 results, these will be the 2 missing munbers
    tahh dahh
    See maths does have some use

  • Is there any way to get unique numbers for a label?

    Im writing a lottery code and would like to know if there is anyway to get my 6 numbers in my label to be different
    this is my code so far
    Public Class frmMain
    Private randGen As New Random
    Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
    Me.Close()
    End Sub
    Private Sub btnSelect_Click(sender As Object, e As EventArgs) Handles btnSelect.Click
    Dim intNum1 As Integer
    Dim intNum2 As Integer
    Dim intNum3 As Integer
    Dim intNum4 As Integer
    Dim intNum5 As Integer
    Dim intNum6 As Integer
    intNum1 = randGen.Next(1, 54)
    intNum2 = randGen.Next(1, 54)
    intNum3 = randGen.Next(1, 54)
    intNum4 = randGen.Next(1, 54)
    intNum5 = randGen.Next(1, 54)
    intNum6 = randGen.Next(1, 54)
    lblNumbers.Text = String.Format("{0}, {1}, {2}, {3}, {4}, {5}", intNum1, intNum2, intNum3, intNum4, intNum5, intNum6)
    End Sub
    End Class

    Here's one way using nested For loops.  This was tested and it works.  It will select 6 different unique numbers between 1 - 54. 
    Private Sub btnOK_Click(sender As System.Object, e As System.EventArgs) Handles btnOK.Click
    Dim num As Integer, dup As Boolean = False
    Dim randnum As New Random()
    Dim strand As String = ""
    Dim itm As String = ""
    For x As Integer = 1 To 6
    For y As Integer = 1 To 6
    num = randnum.Next(1, 55)
    itm = num.ToString()
    If strand.Contains(itm) Then
    dup = True
    x = x - 1
    Exit For
    End If
    Next y
    If dup = False Then strand &= itm & " "
    dup = False
    Next x
    lblRandom.Text = strand
    End Sub
    Here is another way using the Shuffle Sort algorithm with an array:
    Private Sub btnShuffle_Click(sender As System.Object, e As System.EventArgs) Handles btnShuffle.Click
    Dim mix, temp As Integer
    Dim randnum As New Random
    Dim strand(54) As Integer
    lblRandom.Text = ""
    For x As Integer = 1 To 54
    strand(x) = x
    Next
    For x As Integer = 1 To 54
    mix = randnum.Next(1, 55)
    temp = strand(mix)
    strand(mix) = strand(x)
    strand(x) = temp
    Next
    For x As Integer = 1 To 6
    lblRandom.Text &= strand(x).ToString & " "
    Next
    End Sub
    Solitaire

  • Find no numbers  characters in a string

    HI, how i can find no numbers characters in a string
    By example.
    '45125454564#4545'.
    I only want to know if the string contains no number characters or not, i dont want to know the character '#'.
    Is there a function module for doing that?
    Thanks

    You can try:
    NUMERIC_CHECK
    OR
    IF var CO '0123456789'.
    ENDIF.

  • My free trail for $29.99 as run out. want to join but i can't find serial numbers. help!

    my free trail for $29.99 as run out. want to join but i can't find serial numbers. help!

    Cloud programs do not use serial numbers... you download & install & activate by logging in to your paid Cloud account
    http://www.adobe.com/products/creativecloud/faq.html
    http://helpx.adobe.com/creative-cloud/help/install-apps.html
    http://forums.adobe.com/community/download_install_setup/creative_cloud_faq
    what is http://helpx.adobe.com/creative-cloud/help/creative-cloud-desktop.html
    Cloud Getting Started https://helpx.adobe.com/creative-cloud/topics/getting-started.html

  • How to generate unique numbers

    hi all,
    I want to generate unique numbers always starting from 1 using a single sql query and I dont want to use a sequence and i dont think rownum will be helpful for generating unique numbers in all cases . how to do this ?
    thanks & regards,
    kumar.

    If two users get the MAX from temp, they would be updating with the same value for two different rows.If TEMP is a genuine temporary table, this is not an issue, because the data in a temporary table is only visible within a session.
    The big problem with this approach is the mutating table one: we cannot issue the requisite select statement from a BEFORE INSERT trigger. So this solution is only going to work with a view and an INSTEAD OF INSERT trigger.
    Another, more workable, solution is to use a code control table. This can be (should be) another temporary table, with one row holding one column - next value for TEMP.ID. Normally we would rule out such a solution because it serializes access to the inserted table, but as this is only on a per session basis, it doesn't matter.
    CREATE OR REPLACE TRIGGER tmp_bir BEFORE INSERT ON temp1 FOR EACH ROW
    DECLARE
      ln NUMBER;
    BEGIN
      SELECT nvl(code1.next_id,1) INTO ln
      FROM code1;
      :NEW.id := ln;
      UPDATE code1
      SET    next_id := ln+1;
    END;Beware: coded freehand, so may need debugging.
    Cheers, APC

  • Displaying 3 random and unique numbers out of 6

    The following program gives me the results in the output panel because I used trace.  The problem is that I want these numbers displayed when I click on a button.  The numbers should not duplicate when the button is clicked, for example not "3, 3, 2" but "3, 2, 5".  Here is the program that randomly selects numbers (which by the way is not mine):   (I'll happily donate 15$ to the animal charity of your choice for whoever can give me a hand with this problem, thanks!)
    var mynumbers:Array = ["1","2","3","4","5","6"];
    var mystuff:Array = [];
    var randomCount:Number = 3;
    var r:Number;
    for (var i = 0; i<randomCount; i++)
    r = Math.floor(Math.random() * mynumbers.length);
    mystuff[mystuff.length] = mynumbers.splice(r,1);
    trace(mystuff);
    //and here is my button code
    generate_btn.addEventListener(MouseEvent.CLICK, coco);
    //3.;
    function coco(event:MouseEvent):void

    Hi
    I am trying to replace the numbers in the random script with pictures. I thought that all I had to do was replace the numbers in the array with pictures name.
    I am getting the output as picture names instead of actual images. I just started flash a few weeks ago and would appreciate where I am going wrong in the code below. I know, it's a bit ambitious for someone who has no experience in programming or mathematical background. I think, that is the only way to learn. By asking the experts in programming. Otherwise, I just give up, and go back to watching TV.
    var mynumbers:Array = ["alfa.jpg","beta.jpg","alfa1.jpg","alfa2.jpg","alfa3.jpg","alfa4.jpg"];
    var randomCount:Number = 3;
    function shuffle(a:Array) {
        var p:int;
        var t:*;
        var ivar:int;
        for (ivar = a.length-1; ivar>=0; ivar--) {
            p=Math.floor((ivar+1)*Math.random());
            t = a[ivar];
            a[ivar] = a[p];
            a[p] = t;
    //and here is my button code
    generate_btn.addEventListener(MouseEvent.CLICK, coco);
    //3.;
    function coco(event:MouseEvent):void
    shuffle(mynumbers);
    for(var i:int=0;i<randomCount;i++){
    if(!this["tf_"+i]){
    this["tf_"+i]=new TextField();
    this["tf_"+i].text = mynumbers[i];
    addChild(this["tf_"+i]);
    this["tf_"+i].y = i*40;

  • "Unique Key" in an array of elements

    Hi all.
    I'm attaching here a piece of an XSD I'm writing:
              <xs:element name="main_element" maxOccurs="unbounded">
           <xs:complexType>
              <xs:sequence>
                   <xs:element name="key_element" type="xs:string"/>
                      <xs:element name="element_2" type="xs:integer"/>
                 </xs:sequence>
              </xs:complexType>
              </xs:element>What I'd like is defining "key_element" as a unique key of the array "main_element", that is forcing the resulting array not to contain duplicate values for "key_element".
    Is there any way to accomplish that?
    Thanks in advance for any help!

    Define key_element as a key (or unique)! Check the schema specification at http://www.w3.org/TR/xmlschema-1/#cIdentity-constraint_Definitions. If you're up to a challenge translate the specification from W3-ese to a meaningfult language, or take a short cut and read the example in section 3.11.2.
    Support for keys in validation is sometimes spotty, but it's pretty easy to code up your own checks if needed.

  • Alternative to find unique records with 60 character in selection string.

    Hi,
    We have to find out the values from the Infoobject. When we try to display data from an master object, the maximum length of selection it accepts 45 characters only but we need to input data around 60 characters in selection.
    Thing we tried:
    1. Selecting complete data without any condition but it did not work due to large volume of data.
    2. We tried to extract data from RSA3 but it did not work due to large volume of data.
    Please suggest me alternative to find unique records with 60 character in selection string.
    Regards,
    Himanshu Panchal.

    This sounds a bit strange. Are you perhaps mistakenly storing text data incorrectly as the primary key of the master data? I can't think of any actual data that is that length to ensure usinqueness - even GUIDs are maximum 32 characters - but GUIDs don't count as actual "readable" data although you do need to be able to select it from time to time. Perhaps you have a super secure password hash or something like it ?
    Also are you expecting to have a unique single record returned by your selection? To do this would in general REQUIRE that ALL the data is read because master data is not stored in the DB sorted by the data itself, but stored instead sorted by the it's SID.
    When you say you are selecting data from master data, which master data tables are you using? I have been able to select data from very large MD table (15 million unique records) using SE16 with no problems. Just enter the table name, and before you execute just count the number of records - it helps to know what you want to end up with.
    Have you tried using wild cards (the *) to preselect a smaller number of records : * a bit of your 60 character string *
    If you are trying to select from a non-key field you will encounter performance issues, but you can still use the wildcards, and get a result.
    Don't use RSA3 it was designed to make selections and group them into datapackets. It's not the same as selecting directly on the table in SE11 or SE16

  • I need to know how many downloads individual albums and songs had off of iTunes for a project, how do I find these numbers?

    I need to know how many downloads individual albums and songs had off of iTunes for a project, how do I find these numbers?

    Ed...maybe a little less time gaming and a bit more time in English class? They got this thing called punctuation and sentences now. Last things first; there is no amount of money that can change your GPU so you can scratch that expense off the list. So you need a battery and a fan? Where do you live? USA? We can help you find a battery but where did you plan to have the new fan put in? 

  • Finding Missing Numbers

    I want to find missing numbers from a column which is alpha numeric, its last five positions are numeric. At first three positions there are different combinations of alphas i.e. *'BA ','BAW','SA ','SAA' ..........* if alphas are two then 3rd position is blank. I also need it to generalised this to cover all existing alpha numeric series.
    SELECT SUBSTR (a.claim_no, 4, 5) + 1
      FROM core_business.cb_pensioner a
    WHERE SUBSTR (a.claim_no, 1, 3) = 'BA '
       AND NOT EXISTS (
                     SELECT NULL
                       FROM core_business.cb_pensioner b
                      WHERE to_number(SUBSTR (b.claim_no, 4, 5)) =  to_number(SUBSTR (a.claim_no, 4, 5)) + 1)
       order by SUBSTR (a.claim_no, 4, 5);I am getting ORA-01722 error

    You have two issues with such a task.
    Problem 1 is how to convert the trailing part into a number so that you can compare values.
    to_number(SUBSTR (b.claim_no, 4, 5)) works, but only if the value in b.claim_no is always a number regardless of the other column criteria.
    A statement like
    WHERE SUBSTR (a.claim_no, 1, 3) = 'BA ' /* filter 1 */
    and to_number(SUBSTR (b.claim_no, 4, 5)) > 1 /* filter 2 */
    ...might fail because your table might have a value like
    b.claimno = 'XYZ1234b'
    The way you wrote the query the database will decide which filter criteria it executes first. It might be filter1, but could also be filter2. If filter2 is executed first then you will get the error message.
    Problem 2 how to order and compare different rows, so that you can find the missing values.
    Here the analytic LEAD(LAG) function is very helpful. it will give you access to the next (or previous row).
    Both problems can be overcome.
    Here is my try, but I'm not sure if it works in your case. You might need to adapt a little.
    This should work if all the rows are numeric that belong to the specific groups. if you can have wrong data in there too, then a different approach is needed.
    with testdata as (select 'XYZ1234b' claim_no from dual union all
                select 'BA 12345' claim_no from dual union all
                select 'BA 12346' claim_no from dual union all
                select 'BA 12350' claim_no from dual union all
                select 'BAW11111' claim_no from dual union all
                select 'BAW11113' claim_no from dual union all
                select 'XYZ1234b' claim_no from dual )
    /* end of test data creation */
    select claim_no, substr(claim_no, 1,3) part1, substr(claim_no, 4) part2,
           to_number(substr(claim_no, 4)) current_num,
           lead(to_number(substr(claim_no, 4))) over (partition by substr(claim_no, 1,3) order by to_number(substr(claim_no, 4))) next_num,
           lead(to_number(substr(claim_no, 4))) over (partition by substr(claim_no, 1,3) order by to_number(substr(claim_no, 4)))
            - 1 - to_number(substr(claim_no, 4))
            as "missing_values"
    from testdata
    where substr(claim_no, 1,3) in ('BAW','BA ')
    order by claim_no;
    CLAIM_NO PAR PART2 CURRENT_NUM   NEXT_NUM missing_values
    BA 12345 BA  12345       12345      12346              0
    BA 12346 BA  12346       12346      12350              3
    BA 12350 BA  12350       12350
    BAW11111 BAW 11111       11111      11113              1
    BAW11113 BAW 11113       11113Problem 1 is solved because the where condition is always executed before the function in the select clause, especially in connection with an analytic function.
    Problem 2 is also solved by using the analytic function LEAD function. And this is fast, because you access the same table only one time. Other solution might do a subquery to fetch the value from the previous/next row. This means several accesses to the same table and is usually much slower.
    Edited by: Sven W. on Sep 20, 2010 2:32 PM

  • Search numbers from an array

    Hai
         Pls help me how to do this,
    My read CAN data is like this
           First frame -10 11 58 05 52 35 F1 52
    Conse. frame 1 -21 04 E8 52 10 E8 56 11
    Conse. frame 2 -22 E4 56 12 E4 62 11 E4
     i want to extract the red coloured numbers from the array.
    Thanks
    sk
    I am using LabVIEW 7.1 & NI PCMCIA CAN card
    Attachments:
    tttttt.vi ‏82 KB

    If instead you want to extract certain data bytes from each message, you should use the 'Index Array' function from the Array palette.
    This will extract individual elements from the array as specified by the connected Index inputs. The image below shows the setup needed to get the elements for your First Frame.
    Ed
    Message Edited by Ed Dickens on 01-18-2007 07:57 AM
    Ed Dickens - Certified LabVIEW Architect - DISTek Integration, Inc. - NI Certified Alliance Partner
    Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.
    Attachments:
    Index Array.gif ‏13 KB

  • Feeding numbers into an Array

    Hi, I want to feed numbers into an array but its only using the first element. In my vi users can enter a number and this number needs to be then stored in an array. Any help would be welcome. Thanks

    like this maybe?
    Of course you would replace the random number with a control and use an event structure to spin the loop only if the input is changed by the user, for example.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    AddNumbers.png ‏2 KB

  • Converting a string of numbers into an array of booleans

    For a homework assignment, I need to convert a string of numbers into an array of booleans.  The string is a bunch of random numbers (0-9) in sequence, with no spaces.  It looks something like this: 0123452348949230740329817438120947392147809231419.  I need to make it so that each even number represents a "True" boolean and so that each odd number represents a "False" boolean.  I think that I first need to convert each element of the string into a number, and then use a case structure (or something) to say, for each element of the array, "If even, then true.  If odd, then false," but I could be wrong.  Any suggestions?

    billko wrote:
    Hooovahh wrote:
    billko wrote:
    Sounds reasonable.  Think about the definition of "odd" and "even" and it will make life a lot easier. 
    I know you are trying to be vague but I'd like to give a key hint.  Use the Quotient and Remainder function.
    LOL maybe that was one of the objectives of the homework. 
    To be fair it sounds like there is more work that is needed.  A new user of LabVIEW will have a hard time figuring out how to process each character one at a time when it isn't in an array.  
    It's just that most people (me at least) stopped thinking about division with quotient and remainder after basic algebra.  I then of course changed my way of thinking when I used LabVIEW.  Still most of the time when you use division you want to know the fractional part as a decimal.  Thinking this way makes the problem more difficult then it needs to be.
    Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
    If 10 out of 10 experts in any field say something is bad, you should probably take their opinion seriously.

  • How to find Port numbers used by RMI application

    Hi, hope u all find me a solution, how to find port numbers used in the RMI application, that is port number which the RMI application communicates between RMIserver and RMIclient. ur answers would b highly appreciated

    Currently RMI transport layer does not directly expose any public methods to get the listening ports of the exported RMI objects, but the application can always export RMI server objects at certain designated ports instead of relying on the RMI runtime by specifying them to UnicastRemoteObjcect at the time of exporting.
    RMI transport layer try to optimize the number of listeing sockets by exporting all RMI server objects on a single port if no explicit ports were chosen. If the application is really interested in knowing the listeing ports, it can always specify the client and server socket factories to be used for creating Socket and ServerSocket to the RMI runtime at the time of exporting. When a RMI server object is exported, but the listening socket is not yet created, RMI transport layer invokes the createServerSocket(host, port) of server socket factory by passing the host and port details. If no explicit port is specified, underlying socket implementation choses anonymous port. At this point of time application can log these listeing ports to some log file.
    Similarly when the stub to the remote object is de-serialized in the client address space, it does also contain the client socket factory along with the end point details (host, port and server object ID). RMI runtime in the client address space needs to establish connection with the remote server object, it try to get the socket from client socket factory by invoking createSocket() on the client socket factory. Now the application can call getLocalPort() on the socket before returning it to the RMI transport layer.
    There is a undocumented class RMIStat to dump RMI runtime state information. It provides a lot of static methods to dump RMI state information like object table, transports, threads etc. You can download the source code of this utility from RMI archives, but remember this is not a comman-line utility, you must invoke these static methods as part of the application code.
    -- Srinath Mandalapu

Maybe you are looking for

  • Is it possible to backup my work done in Lightroom 4 to include my original cr2 files and changes?

    I want to transfer some of my older work to an external hard drive, but I don't want to lose all the adjustments I made and would almost like to be able to pick up where I left off in the event I want to come back and continue to process images more

  • Can I load address book from spreadsheet? How?

    I had to create my address book spreadsheet from webserver address list. It's on open office spreadsheet. Would like to place it on thunderbird address book. How do I import?

  • Name on print doc for Physical inventory.

    Hi All, When our user run the  Trx MI21 for printing the PI doc ... Print doc contains "created by XYZ user " .  The XYZ user is not exist in the system . The PI doc belongs to year 2004.   Is it possible to get the ''created by " on the print doc  o

  • Host migration problems

    I am in the process of migrating my 12 websites from mobileme to a new hosting service. Using iWeb's FTP option I've been able to publish all the sites except two, which at the very end (once all the files have been transferred) generate a publish er

  • Create Communication Component BS interfaces not loading

    Hello, I have created a communication component and assigned a business system in my new PI 7.1 system and unlike the other components I've create this Business System does not load with all the inbound and outbound interfaces.  When I open the Busin