Count how many time we have each element

I can't count how many the same element is on my array, I have an array [21, 12, 4, 21, 21, 4]
I expect to have something like this:
number exist number
21 3
12 1
4 1
below is the code
System.out.printf("%10s,%10s \n", "number exist", "number");
          for(i = 0; i < list.size(); i++){
               for(int j = 0; j < list.size(); j++){
                    if (list.get(i) == list.get(j))
                         v++;
          System.out.printf("%10s,%10s \n",v,list.get(i));     
Edited by: ronisto on 11-Mar-2008 1:34 PM
Edited by: ronisto on 11-Mar-2008 1:39 PM

good actually I 'm using a List, I could'nt find where is wrong, I can print for the first one, but if I try to use the for it' s not working...look the code below with a list like this [5 , 1, 7, 1, 1, 5]
          System.out.printf("%10s,%10s \n", "Column1", "Column2");
               for(j = 0; j < list.size(); j++){
                         if (list.get(j) == list.get(0))
                              v++;
               System.out.printf("%10s,%10s \n",v,list.get(0));
result give me:
Column1 Column1
3 1
til here is good but when I try to print samething for all elements of my list it doesn't work
System.out.printf("%10s,%10s \n", "number exist", "number");
               for (i = 0; i < list.size(); i++){
                    for(j = 0; j < list.size(); j++){
                         if (list.get(j) == list.get(i))
                              v++;
               System.out.printf("%10s,%10s \n",v,list.get(i));
Edited by: ronisto on 11-Mar-2008 6:04 PM

Similar Messages

  • Counting how many times my app has been opened

    I want to be able to count how many times a user has opened my application, and so every time the application launches, this number is added by one.
    Does anyone know how I store a long-time variable like this that will still need to be available across different runs of the application? I imagine this value would be stored in the application's preference file in Library, but I don't know how to do this.
    Can any of you please lend me some advice/code to achieve this (I am using Objective-C)?
    Thanks in advance,
    Ricky.

    Hi.
    It has been a while - but I finally got around to slapping some code together. I have successfully created and retrieved the value from the preference file, but for some reason, adding 1 to my value each run is not working. It only adds by one after each BUILD. So I have to rebuild it every time I want it to increment. See my code below;
    [NSUserDefaults init];
    int numberOfTimes;
    numberOfTimes = [[NSUserDefaults standardUserDefaults] integerForKey:@"used"];
    numberOfTimes = numberOfTimes++; //It is that that is not working.
    [[NSUserDefaults standardUserDefaults] setInteger:numberOfTimes forKey:@"used"];
    NSLog (@"%d", [[NSUserDefaults standardUserDefaults] integerForKey:@"used"]);
    I can't seem to stop anything wrong, but then again it is late.
    Do any of you see any errors here?
    Thanks,
    Ricky.

  • Any idea why in Numbers my COUNTIFS formula keeps breaking? For daycare purpose, I use a spreadsheet that helps me to count how many children I have at 3:15, 4:15 and 5:00. COUNTIFS works well when I create it but breaks after a while. Also I am using a p

    Any idea why in Numbers my COUNTIFS formula keeps breaking? For daycare purpose, I use a spreadsheet that helps me to count how many children I have at 3:15, 4:15 and 5:00. COUNTIFS works well when I create it but breaks after a while. Also I am using a pop-up menu in the cells in time format, does it have any consequence on the formula?

    Any idea why in Numbers my COUNTIFS formula keeps breaking? For daycare purpose, I use a spreadsheet that helps me to count how many children I have at 3:15, 4:15 and 5:00. COUNTIFS works well when I create it but breaks after a while. Also I am using a pop-up menu in the cells in time format, does it have any consequence on the formula?

  • Hey! On excel I want to count how many time a text come back in the spreadshit (sum) thx, hey! On excel I want to count how many time a text come back in the spreadshit (sum) thx

    Excel:
    line of cellule with 3 different text. I want to count have many time a text come in the line... Thx for helping me, it is for my job!!

    Hopefully I am understanding your question.
    A typical way to count how many times a word appears in a line of text in a cell is to substitute spaces for the word, one less space than the length of the word. Example:
    A1 has the string "brown red brown green"
    A2 =LEN(A1) - LEN(SUBSTITUTE(A1,"brown","    "))  
    "brown" has five letters so there are four spaces in the substitution text)
    If you want to do several cells at once, counting the total number of times the word appears, concatenate the cells with a space between them
    A1 and A2 have text in them
    A3 =LEN(A1&" "&A2) - LEN(SUBSTITUTE(A1&" "&A2,"brown","    "))

  • How to count how many times the caller calls by using UCCX script?

    Hi there,
    My customer wants to do a few changes for their script as below:
    At the beginning of the script they are planning to add a new menu item, it will announce their new privacy policies and to continue the user must press the number one to continue to the Welcome.  If they do not press 1 then the message should repeat itself and if they again do not press 1 they should be transferred over to a live operator who will explain things and then be able to transfer them back to the message so that they can press 1 and continue.
    I modified their script as attached file, but i don't know how to count how many times the caller calls in "Get Reporting Statistic".
    Any helps would be appreciated.
    Thanks.

    Hi Aaron,
    At beginning, i want to use a variable to get number of mistake for the same caller, then we will send the call to right place to fulfill the customers' needs. 
    Do you have any suggestion for the new posted script?
    Thanks.

  • How do you count how many times a if/when/for statement runs?

    So this new program I'm trying to write is a changemaker (in euros for some reason). You enter a price of a product, amount paid, and it computes how much change you should get back in the form
    [number] x 2-euro
    [number] x euro
    [number] x 20-cent
    etc
    Where the number is the number of that kind of coin they should get back.
    Right now, I have it so that you enter price, and amount paid, and then I have a series of while statements that go like..
    while (surplus > 2.00);
    while (surplus > 1.00);
    etc. If the surplus > 2, I want to add 1 2-euro coin to the count, subtract 2, and then recheck the amount and either add another 2-euro or go onto the next coin. Only thing is, I don't know how to count how many times a while statement ran until it was false. Or I could be looking at this the wrong way entirely. What's the best way to go about a program like this?

    Well I finally figured it out with lots of help from other students in the class. It was much easier than it appeared to be. Thanks for the hints everyone (especially joker for doing the coding for it) wow :D much appreciated ^^
    Heres the code that I came up with and it works matches the assignment's example:
    import java.util.* ;
    public class ChangeMaker {
         private static int changeA [] = new int [7] ;
         private static float changeVar[] = new float [7] ;
         private static int changeVarNumb[] = new int [7] ;
         private static String changeNames[] = new String [7] ;
         // initialize Scanner
         private static Float getInput (String prompt){
              System.out.print (prompt.concat(" ")) ;
              Scanner sc1 = new Scanner (System.in) ;
              return (sc1.nextFloat ()) ;
         // put the change variables and change names into arrays
         private static void moneyArray (){
              changeVar[0] = (float) 2.0 ;
              changeVar[1] = (float) 1.00 ;
              changeVar[2] = (float) 0.20 ;
              changeVar[3] = (float) 0.10 ;
              changeVar[4] = (float) 0.05 ;
              changeVar[5] = (float) 0.02 ;
              changeVar[6] = (float) 0.01 ;
              changeVarNumb[0] = 2 ;
              changeVarNumb[1] = 1 ;
              changeVarNumb[2] = 20 ;
              changeVarNumb[3] = 10 ;
              changeVarNumb[4] = 5 ;
              changeVarNumb[5] = 2 ;
              changeVarNumb[6] = 1 ;
              changeNames[0] = (String) "Euro" ;
              changeNames[1] = (String) "Euro" ;
              changeNames[2] = (String) "Cent" ;
              changeNames[3] = (String) "Cent" ;
              changeNames[4] = (String) "Cent" ;
              changeNames[5] = (String) "Cent" ;
              changeNames[6] = (String) "Cent" ;
              return ;
         // calculate the change the user is going to receive
         private static void calcChange(float diffAmount) {
              for (int i = 0; i < changeVar.length ; i++) {
                   if (diffAmount > changeVar) {
                        changeA[i] = (int)(diffAmount / changeVar[i]);
                        diffAmount = diffAmount - (changeA[i] * changeVar[i]) ;
                        System.out.println(changeA[i] + " x " + changeVarNumb[i] + " " + changeNames[i]) ;
              return;
         // output
         public static void main(String[] args) {
              float itemPrice = getInput("Enter product price: ") ;
              float amountTendered = getInput("Enter amount paid: ") ;
              float diffAmount = amountTendered - itemPrice ;
              System.out.println() ;
              System.out.println("Your change is " + diffAmount + " euros") ;
              moneyArray() ;
              calcChange(diffAmount) ;
    And the output looks like this:
    Enter product price:  2.32
    Enter amount paid:  5.00
    Your change is 2.68 euros
    1 x 2 Euro
    3 x 20 Cent
    1 x 5 Cent
    1 x 2 Cent
    1 x 1 Cent                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Hi, I want to know if in the AppStore exist an app that count how many messages I have been used. Thanks

    Hi, I want to know if in the AppStore exist an app that count how many messages I have been used

    Some carriers have iOS apps that will tell you this info...see if yours does, or can't you just login to your account online & see such info?

  • How to count " How many times the ' commit work ' Statement is executed.

    Hi all sap Champions,
    One of the client requirement, That is
    How to count " How many times the ' commit work ' Statement is executed.
    It's urgent.
    Please can anybody help me for this.
    Thanks
    Basu

    hi,
    when report try like this.
    declare a variable as
    data: counter type i value 0.
    COMMIT.
    counter = counter + 1.
    write:/10 counter 'NO. OF TIMES COMMIT WORKED'.

  • Something to count how many times form has downloaded

    Hi there.
    DW CS3, PHP mySQL
    I want to put on my site a PDF document that people can
    download.
    I don't want to link this to my mySQL DB for the records to
    be added in the
    DB.
    But, I want to see how many times this document has been
    downloaded.
    It's almost like "autonumber" in Access.
    I will really appreciate any advise and direction on how to
    accomplish
    this.
    Thanx so much.
    Deon

    Thanx Joe, I will check it out.
    I'm quickly building the download page.
    Deon
    Joe Makowiec <[email protected]> wrote in
    news:[email protected]:
    > On 14 Oct 2008 in macromedia.dreamweaver, Deon H wrote:
    >
    >> I want to put on my site a PDF document that people
    can download.
    >> I don't want to link this to my mySQL DB for the
    records to be added
    >> in the DB.
    >>
    >> But, I want to see how many times this document has
    been downloaded.
    >> It's almost like "autonumber" in Access.
    >> I will really appreciate any advise and direction on
    how to
    >> accomplish this.
    >
    > It's available in your logs. Just do a search for
    "myfile.pdf", and
    > look for lines which have a 200 status code. (Status
    code of 206
    > indicates a resumed download; you don't want to count
    those.) A
    > recent sample; details changed to protect the guilty:
    >
    > 192.168.4.246 - - [14/Oct/2008:01:56:04 +0000] "GET
    > /documents/town20080911.pdf HTTP/1.1" 200 20101
    > "
    http://www.example.org/minutes.asp"
    "Mozilla/4.0 (compatible; MSIE
    > 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)"
    192.168.4.246 - -
    > [14/Oct/2008:01:56:04 +0000] "GET
    /documents/town20080911.pdf
    > HTTP/1.1" 206 18572 "-" "Mozilla/4.0 (compatible; MSIE
    6.0; Windows NT
    > 5.1; SV1; .NET CLR 1.1.4322)"
    >
    > The first field is the IP address that the request came
    from
    > The second is date/time (in this case, in GMT)
    > The third is the request with protocol
    > The fourth is status code[1] followed by bytes
    transferred
    > The fifth is referrer; the sixth is user agent
    >
    > More information:
    http://www.w3.org/TR/WD-logfile.html
    >
    > [1]
    http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
    >

  • I had set my passcode by pressing 1 repeatedly till it filled the passcode box. I dont know how many times I have pressed 1. Can someone tell me the character length of the text box of the Passcode

    Hi,
    My son foolishly pressed a single digit till it just filled the text box of the passcode. Now i dont know how many times he has pressed it. If I can know the charcter length, or how many digits can just fill the text box of passcode, I can unlock my ipad2. If anyone reading this has ipad2, he can do the same thing and count how many digits will just fill the text box. I will really appreciate the help.
    Thanks

    You can put the iPad into Recovery mode and Restore it. See this link and note the sentence commencing, 'If you restore from a different computer.... ' down near the bottom of the page.
    http://support.apple.com/kb/HT1808

  • Cycle counting - How many times an item has been counted?

    Hallo Gurus,
    do you know if there's a way to know how many times an item has been counted during the year?
    Thank you very much indeed.
                Mick

    Hi Mick,
    Check the below links. Hope they will help you.
    http://help.sap.com/saphelp_snc70/helpdata/EN/4c/c1b4b55b912a4ae10000000a42189b/content.htm
    http://help.sap.com/saphelp_46c/helpdata/en/4d/2b8e3d43ad11d189410000e829fbbd/content.htm
    Regards,
    Shilpa

  • How can I count how many songs I have?

    In ITunes, when I select "songs", it used to say at the bottom how many songs I had and how many Gb of space it used, now it doesn't.  Is there a way to see how many songs I have without counting them all?
    Thanks,
    Ehren

    Click View on the menu bar at the top of your screen, then click Show Status Bar.

  • Count how many times a Orchestrator runbook has run in last 30 days

    Hi
    Please could someone help me with a sql query that could help me do a count on how many times a runbook has run or been executed in the last 30 days ?
    Thanks

    Hi,
    here is your SQL Query
    select Name, count(policies.UniqueID) as Count from Policies
    inner join POLICYINSTANCES on policies.UniqueID=POLICYINSTANCES.PolicyID
    where POLICYINSTANCES.TimeEnded > DATEADD(mm,-1,GETDATE())
    group by name order by Count
    Seidl Michael | http://www.techguy.at | twitter.com/techguyat |
    facebook.com/techguyat |
    youtube.com/techguyat

  • How can I determine how many times I have down loaded a song? Max is 7 times?

    How do I determine the # of times a song has been down loaded? Max is 7?

    Jim, I apprecite your help. Im still  lost...not that efficient on computer. Some notes, If burn playlist to disc doesn appear in the menu, it means that the playlist you selected cant be burned to a CD because it contains items that have usage restrictions;  if the playist contains itunes store purchases that are not itune plus songs, you can burn the playlsit to a CD up to 7 times;  DRM - Digital Rights Management????  Any help is appreciated Thank You

  • Counting how many times file is downloaded

    Hi,
    In my web application I need to set the limit say 10 times, a file can be downloaded by the user. After downloading 10 times I need to disable the download link. I am using javascript,
    ajax and spring framework and mysql .
    Problem is when the file is being downloaded if the user clicks on cancel button of browser download manager or if they closes the browser , download count is incremented though the file is not downloaded completely. I need to catch the events when the download is incomplete so that I should not increment the download count that time.
    Is there any way to solve this problem?
    Please help me.....

    I'm not sure if there's an easy way to do what you want to do.
    You could try using a Servlet to serve the file though. What you'd basically need to do is set up a servlet to take a "file" parameter, load up the file, and then send it to the output stream. Once that was done you could increment the file download count.
    So, in pseudo-code, what you'd be doing is:
    doGet(HttpServletRequest request, HttpServletResponse response)
      String filename = request.getParameter("filename");
      File f = new File(FILE_DIR + filename);
      if (downloadCount < MAX_DOWNLOAD_COUNT)
        // TODO: Create FileInputStream and write contents to response.getOutputStream()
       // If you're using Spring, looking into the FileCopyUtils class as this will make it much easier
       // Increment download count
        downloadCount++;
    }When someone clicks the "cancel" button on a download, you should find this closes the output stream, which will throw an exception and your download count will not be incremented. You might want to verify that though by testing it!
    Of course, in the interests of security you would need to check that the filename being passed in didn't contain any special characters (particularly backslashes or forward slashes).
    And I don't know how you're storing the download count, but of course you'd probably want to modify it so that it stored on a "per-file" basis!

Maybe you are looking for

  • Really lost using iMovie since Mav update

    Imported four Hi 8 tapes.  Apparently they all went to "updated projects".  can't find them.  Did another two, twice Imovie quit unexpectedly, got an Apple message.  How can I import some Hi8 tapes through my analog digital converter and get the vide

  • Using CAC intead of java KeyStore

    Does anybody know if it is possible to instruct java application to use CAC instead of a jks file when x509 certificate is required to access a resource? System.setProperty("javax.net.ssl.keyStore", "mystore.jks"); I have a requirement for a swing ap

  • Has anyone received the following error after updating to the Yosemite 10.10.1/2 OS?

    *** Collection <_NSArrayM: 0x618001059620> was mutated while being enumerated. This issues arises when opening, editing, and placing contents in PS. Issue only visible within PS.

  • Problem on install Dreamweaver CS3 on Vista

    I tried to install Dearmweaver CS3 on Microsoft window buisness 6.0.6001 but when the insaller startup is apear for a seconds then disapear i tried to search in the forums but all problems there after this step

  • Error when Customer message create

    Dear All, when i create the new message from service.sap.com,the System ID, Name and Installation Number is disable, so i am unable to create the new message. Only System Search is visible. When i Double click on the System ID or Installation No. The