Counting items in the array

Hello,
I need a clean way to count the items in an array. I can sort them using :
int []x=new int[150]; I'm using Math.random%10 to get intergers from 0-9;
public static void countItem() // sort items in the array
int min, temp;
for (int i = 0; i < x.length-1; i++)
min = i;
for (int scan = i+1; scan < x.length; scan++)
if (x[scan] < x[min])
min = scan;
// Swap the values
temp = x[min];
x[min] = x;
x[i] = temp;
but once they are sorted I am baffeled on a clean way to count how many of each item are listed.
0001122222222333444444 etc up to 9.
Thanks

but once they are sorted I am baffeled on a clean way to count how many of each item are listed.
0001122222222333444444 etc up to 9I think you're going about this the wrong way. First count, then you've implicitly sorted them (counting sort). public class CountingSort
    public static void main(String[] args)
        int[] arr = {4, 5, 1, 3, 3, 3, 7};
        countSort(arr);
        for (int i = 0; i < arr.length; i++)
            System.out.print(arr[i] + " ");
    static void countSort(int[] arr)
        // Assume all elements of arr are in range 0..9
        // initialise buckets to an array of zeroes - don't rely on this except in Java
        int[] buckets = new int[10];
        for (int i = 0; i < arr.length; i++)
            buckets[arr]++;
// Now reconstruct the array in sorted order
// k is the next element in the array to fill in
int k = 0;
for (int i = 0; i < arr.length; i++)
while (buckets[i]-- > 0)
arr[k++] = i;

Similar Messages

  • Show/Hide certain items in an array of clusters

    I am trying to figure out how to programmatically show/hide certain items in a cluster (specifically an array of clusters).  I tried a couple of things but nothing worked for me.  On a similar note, I would like to be able to programmatically hide certain columns in a table.  I can’t figure it out and the postings on the LabVIEW forums here were either not terribly helpful for my situation or maybe I just didn’t understand them.  I have attached a vi where I tried to hide items within the array of clusters.  Maybe someone could point out why it didn’t work and hopefully they could provide a solution or direction for me to follow.  Thanks in advance…
    Solved!
    Go to Solution.
    Attachments:
    make column hidden.vi ‏15 KB

    Creating a property node directly to the cluster element is far easier. pcardinale essentially shows this.
    As for the question regarding the table columns, there is no direct way to hide the table columns, viz-a-viz Excel. The closest you can get is to set the column width to zero, as shown in attached example.
    Attachments:
    hide table columns.vi ‏13 KB

  • How would I count items in DataSet2 and have them grouped by the column that is tied to DataSet1?

    Greetings!
    First, thank you for looking at my question. I am trying to count the number of items that = "True" in DataSet2 and display them in the "Week" column in a table who is pointed to DataSet1.
    I have a simple table that is set up something like this:
    CDC Week |
    [Week Number] from DataSet1
    | Total
    Count of Some Item |
    [CountSomeField] from DataSet1
    | [ Total of Row]
    Count of Another Item | 
    [CountOfTrueItems] from DataSet2
    | [Total of Row]
    With the expected results:
    CDC Week |
    25
    | 26 |
    27 |
    (n/a)
    Count of Some Item |
    10 |
    20 |
    30 |
    (Expected 60 but not working yet)
    Count of Another Item |
    5 |
    10 |
    15 |
    (Expected 30 but not working yet)
    Instead I get:
    CDC Week |
    25 |
    26 |
    27 | 
    (n/a)
    Count of Some Item |
    10 |
    20 |
    30 |
    (Not working yet)
    Count of Another Item |
    30 |
    30 |
    30 |
    (Not working yet)
    DataSet1 has a few columns including a "Week" column. DataSet2 has two columns, "WEEK" and "POS".
    I need to count items when POS = "TRUE" in DataSet2 and group them on the "Week" column.
    My current expression is =SUM(IIF(Fields!Pos_.Value = "True", 1, 0), "DataSet2")
    And while this returns a value, it does not count (or sum) by each week. I am missing something...
    Thank you for any assistance!
    p.s. Sorry My html skills are not shining with the table formatting :(

    Hi,
    Would you please provide some screenshots?
    Work hard, play harder!

  • [Question]how to count the occurance of numbers inside the array

    im just practicing my java skill but i cant get my program work can you give me guys some idea on how to determine a number that occured more than 1 inside the array e.g i have 10 elements and inside of my offset i have
    1,2,5,4,5,6,5,8,9,5
    and what im planning to do is count the occurances of the number who occures more than 1 and for that 5 occur 3 times how my program can know that i use for loop but cant figure out how to filter the occurances of numbers inside
    my offset
    thank's

    Encephalopathic you said put - 1 instead i did - 2
    public class sample
       public static void main(String args[])
          int num[] = {2,2,2};
          int index1, count = 0, find = 0;
          for(index1 = 0; index1 < num.length - 2; index1++)
             for(int index2 = 0; index2 < num.length; index2++)
                if(num[index2]==num[index1])
                  find = num[index2];
                  count++;
             System.out.println("i found " + find + " " + count + " same number inside your offset");
    }output is:
    i found 2 3 same number inside your offset
    but another question is what if i want my program to tell the other number that occur 1 time
    like this:
    i found 1 2 same number inside your offset
    i found 2 0 same number inside your offset
    i found 1 2 same number inside your offset

  • Sum GETPIVOTDATA with multiple data item references using Array formula and cell references

    I'm trying to build a single formula referencing a shared pivot table. I would prefer not to create additional pivot tables etc.
    My criteria is basically the sum of multiple items in the pivot table. I am able to add multiple fields by typing item names in manually (see below Claims 1/2/3 etc) however I would also like to add a date range array in, but instead of typing them
    in I'd like to use cell values that can change dynamically, depending on previous options selected.
    My current formula is:
    {=SUM(IFERROR(GETPIVOTDATA("Count",'Settlement Pivots'!$A$1,"Loss Fin Year",$B6,"Scheme","Old Scheme","Month",{[Cell Range/Indirect Here...]},"Team2",{"Claims 1","Claims 2","Claims
    3","Claims 4","Claims 5","Major Claims","Claims Services"},"Scope","Settlement"),0))}
    Is this possible?
    Cheers

    Hi,
    Thank you for posting in the MSDN Forum.
    This forum is for developers disscussing issuses about VBA, VSTO and apps for Office. Since the issue is more relate to the end-user, I suggest you getting more effective response from
    Excel IT pro forum.
    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us.
    Thanks for your understanding.
    Best regards
    Fei
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How to count and display the number of records in a database table

    My webpage has a list of items and their details, every item has a button
    Read / Make comments that loads the item in its own page displaying
    a comments form and previous comments.
    This is all working fine.
    I would like to add to each item information stating how many comments have
    been made about that item.
    Allowing the user to see before hand if it is worth while clicking on the
    Read / Make comments button.
    Ideally each item will have a different number of comments.
    The problem I have is outputing the number of comments associated with each item.
    My comments table is called guest my items table is called titles.
    I'm sure mysql statement is correct -
    The table guest currently has 7 comments,
    Item 1 has 3 comments
    Item 2 has 2 comments
    Item 3 has 1 comment
    Item 4 has 1 comment
    When I test the query in dreamweaver
    $Recordset1 = "SELECT COUNT(guest.software_id) as COUNT, titles.id FROM titles LEFT JOIN guest ON titles.id = guest.software_id GROUP BY guest.software_id";
    the outoput is a list showing 2, 3, 1, 1
    My problem is, getting the totals into my repeat region.
    I tried the following line
    <td align="left" valign="top" bgcolor="#e5f8cb">Current comments:<?php echo $row_Recordset1['COUNT']; ?></td>
    resulting in all comments so far displaying 0
    I have highlighted in bold the parts that I am having difficulty with.
    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
      if (PHP_VERSION < 6) {
        $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;   
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      return $theValue;
    $colname_rsTitles = "-1";
    if (isset($_GET['id'])) {
      $colname_rsTitles = $_GET['id'];
    mysql_select_db($database_abe, $abe);
    $query_rsTitles = sprintf("SELECT title, company, `description`, resources, location, url, image, keyword, copies FROM titles WHERE id = %s ORDER BY id ASC", GetSQLValueString($colname_rsTitles, "int"));
    $rsTitles = mysql_query($query_rsTitles, $abe) or die(mysql_error());
    $row_rsTitles = mysql_fetch_assoc($rsTitles);
    $totalRows_rsTitles = "-1";
    if (isset($_GET['id'])) {
      $totalRows_rsTitles = $_GET['id'];
    $colname_rsTitles = "-1";
    mysql_select_db($database_abe, $abe);
    $query_rsTitles = sprintf("SELECT title, company, `description`, resources, location, url, image, keyword, copies FROM titles WHERE id = %s ORDER BY id ASC", GetSQLValueString($colname_rsTitles, "int"));
    $rsTitles = mysql_query($query_rsTitles, $abe) or die(mysql_error());
    $row_rsTitles = mysql_fetch_assoc($rsTitles);
    $totalRows_rsTitles = mysql_num_rows($rsTitles);
    mysql_select_db($database_abe, $abe);
    $query_rs_comments = "SELECT * FROM guest";
    $rs_comments = mysql_query($query_rs_comments, $abe) or die(mysql_error());
    $row_rs_comments = mysql_fetch_assoc($rs_comments);
    $totalRows_rs_comments = mysql_num_rows($rs_comments);
    mysql_select_db($database_abe, $abe);
    $query_rs_users = "SELECT * FROM users";
    $rs_users = mysql_query($query_rs_users, $abe) or die(mysql_error());
    $row_rs_users = mysql_fetch_assoc($rs_users);
    $totalRows_rs_users = mysql_num_rows($rs_users);
    mysql_select_db($database_abe, $abe);
    $query_Recordset1 = "SELECT COUNT(guest.software_id) as COUNT, titles.id FROM titles LEFT JOIN guest ON titles.id = guest.software_id GROUP BY guest.software_id";
    $Recordset1 = mysql_query($query_Recordset1, $abe) or die(mysql_error());
    $row_Recordset1 = mysql_fetch_assoc($Recordset1);
    $totalRows_Recordset1 = mysql_num_rows($Recordset1);
    mysql_select_db($database_abe, $abe);
    if(!isset($_POST['softwareLevel'])){
    if (!isset($_GET['class_id'])) {
    //show all software titles
    $query_rsTitles = "SELECT id, title, company, `description`, resources, location, url, image, keyword, copies FROM titles ORDER BY id ASC";
    }else{
    //show software titles filtered by Literacy of Numeracy (using URL GET variable)
    $query_rsTitles = "SELECT id, title, company, `description`, resources, location, url, image, keyword, copies FROM titles WHERE titles.class_id = ". GetSQLValueString($_GET['class_id'], "int") ." ORDER BY id ASC";
    }else{
    //show software titles filtered by Level (using Form POST variable)
    $query_rsTitles = "SELECT id, title, company, `description`, resources, location, url, image, keyword, copies FROM titles WHERE titles.level_id = ". GetSQLValueString($_POST['softwareLevel'], "int") ." ORDER BY id ASC";
    $rsTitles = mysql_query($query_rsTitles, $abe) or die(mysql_error());
    $row_rsTitles = mysql_fetch_assoc($rsTitles);
    $totalRows_rsTitles = mysql_num_rows($rsTitles);
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <?php $pagetitle="ABE Software Locator"?>
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title><?php echo $pagetitle ?></title>
    <link rel="stylesheet" href="../../includes/styles.css" type="text/css" media="screen" />
    <style type="text/css">
    body {
    background-color: #FFF;
    </style>
    </head>
    <body>
    <?php include("../../includes/header.php"); ?>
        <div><table width="70%" border="0" align="center" cellpadding="3" cellspacing="0">
      <tr>
        <td width="29%" height="50" align="center"><a href="software_detail.php">Back to Locator</a></td>
        <td width="50%" align="center"><a href="../../index.php">Welcome Page</a></td>
        <td width="21%" align="center"><a href="../../logout.php">Log Out</a></td>
      </tr>
      <tr>
        <td colspan="3" align="center"><strong> There Are <span class="totalrecordsnumber"><?php echo $totalRows_rsTitles ?></span>  Software Titles Listed</strong></td>
      </tr>
      <tr>
        <td> </td>
        <td> </td>
        <td> </td>
      </tr>
    </table>
        <?php do { ?>
          <table width="820" border="0" align="center" cellpadding="3" cellspacing="2">
            <tr>
              <td width="206" height="200" rowspan="3" align="center" bgcolor="#FFFFFF"><img src="images/<?php echo $row_rsTitles['image']; ?>" alt="<?php echo $row_rsTitles['title']; ?>" /></td>
              <td colspan="3" align="center" bgcolor="#086b50"><h2><?php echo $row_rsTitles['title']; ?></h2></td>
            </tr>
            <tr>
              <td colspan="3" align="center" bgcolor="#f6b824"><strong>Made by:</strong> <?php echo $row_rsTitles['company']; ?></td>
            </tr>
            <tr>
              <td colspan="3" align="left" valign="top" bgcolor="#e5f8cb"><p class="ptaglineheight"><strong>Description: </strong><?php echo $row_rsTitles['description']; ?></p></td>
            </tr>
            <tr>
              <td colspan="2" align="left" valign="top" bgcolor="#e5f8cb"><span class="tabletext"><strong>Keywords</strong></span><strong>: </strong><?php echo $row_rsTitles['keyword']; ?></td>
              <td colspan="2" align="left" valign="top" bgcolor="#e5f8cb"><strong>Resources:</strong> <?php echo $row_rsTitles['resources']; ?></td>
            </tr>
            <tr>
              <td colspan="4" align="left" valign="top" bgcolor="#e5f8cb"><strong>Web Address:</strong> <a href="<?php echo $row_rsTitles['url']; ?>" target="_blank"><?php echo $row_rsTitles['url']; ?></a></td>
            </tr>
            <tr>
              <td colspan="3" align="left" valign="top" bgcolor="#e5f8cb"><strong>Is installed on:</strong> <?php echo $row_rsTitles['location']; ?></td>
              <td width="195" align="left" valign="top" bgcolor="#e5f8cb"><strong>Copies available:</strong><?php echo $row_rsTitles['copies']; ?></td>
            </tr>
            <tr>
              <td colspan="3" align="left" valign="top" bgcolor="#e5f8cb"><a href="fulltitle.php?software_id=<?php echo $row_rsTitles['id']; ?>&amp;id=<?php echo $row_rsTitles['id']; ?>">Read / Make Comments About This Software</a></td>
              <td align="left" valign="top" bgcolor="#e5f8cb">Current comments:<?php echo $row_Recordset1['COUNT']; ?></td>
            </tr>
          </table> 
          <br />
          <?php } while ($row_rsTitles = mysql_fetch_assoc($rsTitles)); ?>
        </div>
        <?php include("../../includes/footer.php"); ?>
    </body>
    </html>
    <?php
    mysql_free_result($rsTitles);
    mysql_free_result($rs_comments);
    mysql_free_result($rs_users);
    mysql_free_result($Recordset1);

    I changed the mysql as you suggested GROUP BY titles.id
    and added a while loop to iterate over the data
    mysql_select_db($database_abe, $abe);
    $query_Recordset1 = "SELECT COUNT(guest.software_id) as COUNT, titles.id FROM titles LEFT JOIN guest ON titles.id = guest.software_id GROUP BY titles.id";
    $Recordset1 = mysql_query($query_Recordset1, $abe) or die(mysql_error());
    $row_Recordset1 = mysql_fetch_assoc($Recordset1);
    $totalRows_Recordset1 = mysql_num_rows($Recordset1);
    $row_Recordset1 = mysql_query($query_Recordset1) or die(mysql_error());
    <td>Current comments:<?php
    if($row_Recordset1)
    while($row = mysql_fetch_array($row_Recordset1))
    echo $row['COUNT'];
    } ?></td>
    The first item now displays the following,
    comments:2311000000000000000000000000000
    all others
    comments:
    the number matched the database table exactly, 30 records 4 of which have 2, 3, 1, 1 comments.
    It looks as if the problem is trying to get the repeat region to pick up on it!

  • How to get items from a list that has more items than the List View Threshold?

    I'm using SharePoints object model and I'm trying to get all or a subset of the items from a SharePoint 2010 list which has many more items than the list view threshold (20,000+) using the SPList.GetItems() method. However no matter what I do the SPQueryThrottledException
    always seems to be thrown and I get no items back.
    I'm sorting based on the ID field, so it is indexed. I've tried setting the RowLimit property on the SPQuery object(had no effect). I tried specifying the RowLimit in the SPQuerys ViewXml property, but that still throws a throttle exception. I tried using the
    ContentIterator as defined here:http://msdn.microsoft.com/en-us/library/microsoft.office.server.utilities.contentiterator.aspx,
    but that still throws the query throttle exception. I tried specifying the RowLimit parameter in the ProcessListItems functions, as suggested by the first comment here:http://tomvangaever.be/blogv2/2011/05/contentiterator-very-large-lists/,
    but it still throws the query throttle exception. I tried using GetDataTable instead, still throws query throttle exception. I can't run this as admin, I can't raise the threshold limit, I can't raise the threshold limit temporarily, I can't override the lists
    throttling(i.e. list.EnableThrottling = false;), and I can't override the SPQuery(query.QueryThrottleMode = SPQueryThrottleOption.Override;). Does anyone know how to get items back in this situation or has anyone succesfully beaten the query throttle exception?
    Thanks.
    My Query:
    <OrderBy>
        <FieldRef Name='ID' Ascending='TRUE' />
    </OrderBy>
    <Where>
        <Geq><FieldRef Name='ID' /><Value Type='Counter'>0</Value></Geq>
    </Where>
    My ViewXml:
    <View>
        <Query>
            <OrderBy><FieldRef Name='ID' Ascending='TRUE' /></OrderBy>
            <Where>
                <Geq><FieldRef Name='ID' /><Value Type='Counter'>0</Value></Geq>
            </Where>
        </Query>
        <RowLimit>2000</RowLimit>
    </View>
    Thanks again.

    I was using code below to work with 700000+ items in the list.
    SPWeb oWebsite = SPContext.Current.Web;
    SPList oList = oWebsite.Lists["MyList"];
    SPQuery oQuery = new SPQuery();
    oQuery.RowLimit = 2000;
    int intIndex = 1;
    do
    SPListItemCollection collListItems = oList.GetItems(oQuery);
    foreach (SPListItem oListItem in collListItems)
    //do something oListItem["Title"].ToString()
    oQuery.ListItemCollectionPosition = collListItems.ListItemCollectionPosition;
    intIndex++;
    } while (oQuery.ListItemCollectionPosition != null);
    Oleg
    Hi Oleg, thanks for replying.
    The problem with the code you have is that your SPQuery object's QueryThrottleMode is set to default. If you run that code as a local admin no throttle limits will be applied, but if you're not admin you will still have the normal throttle limits. In my
    situation it won't be run as a local admin so the code you provided won't work. You can simulate my dilemma by setting the QuerryThrottleMode  property to SPQueryThrottleOption.Strict, and I'm sure you'll start to get SPQueryThrottledException's
    as well on that list of 700000+ items.
    Thanks anyway though

  • Help! Quiz - need to count score at the end

    I have a working quiz but I want to know how to get the score of the number of correct answers the person got but I can't seem to figure out the code for it. This is my code below. Can someone help me?
    stop();// movie clip waits on buttons
    gloss_mc._visible = false;// set the gloss initially to not visible
    score_int = 0;// score on the quiz is initially zero
    // button functions
    q1_btn.onRelease = function() {
        scoreQuiz_fnc("1");
    q2_btn.onRelease = function() {
        scoreQuiz_fnc("2");
    q3_btn.onRelease = function() {
        scoreQuiz_fnc("3");
    q4_btn.onRelease = function() {
        scoreQuiz_fnc("4");
    function scoreQuiz_fnc(ansSelected) {
        trace("scoreQuiz_fnc ("+ansSelected+")");
    // define answer key
    answerkey_arr = new Array();
    answerkey_arr[1] = '2';// the answer to the question on frame 1
    answerkey_arr[2] = '4';// the answer to the question on frame 2
    answerkey_arr[3] = '3';// ... etc.
    answerkey_arr[4] = '4';
    answerkey_arr[5] = '3';
    answerkey_arr[6] = '1';
    answerkey_arr[7] = '3';
    answerkey_arr[8] = '4';
    answerkey_arr[9] = '1';
    answerkey_arr[10] = '2';
    glosskey_arr = new Array();// create array of gloss responses
    glosskey_arr[1] = 'The correct answer is: Congenital heart defect.';
    glosskey_arr[2] = 'The correct answer is: Four areas of the heart are defected because "tetra" means four. ';
    glosskey_arr[3] = 'The correct answer is: Two left valves because there is only a right and left valve.';
    glosskey_arr[4] = 'The correct answer is: Ventricular Septal Defect because this is when there is a hole (septum) between the right and left ventricles..';
    glosskey_arr[5] = 'The correct answer is: Babies because this condition congenital meaning at birth.';
    glosskey_arr[6] = 'The correct answer is: There is not enough oxygen carried within the blood which causes a discolouration in infants.';
    glosskey_arr[7] = 'The correct answer is: Heart murmur because this condition occurs at the heart.';
    glosskey_arr[8] = 'The correct answer is: After crying, during bowel movements or the occurrence of kicking legs in awakening.';
    glosskey_arr[9] = 'The correct answer is: Shunt because you cannot place the other objects in a heart.';
    glosskey_arr[10] = 'The correct answer is: Heart.';
    function nextQuestion_fnc() {
        gloss_mc._visible = false;// hide the gloss
        nextFrame();// advance timeline to the next question
    // score the answer selected by user
    function scoreQuiz_fnc(ansSelected) {
        trace("For question "+_currentframe);
        trace("scoreQuiz_fnc("+ansSelected+")");
        //if the answer key for this question matches the answer selected
        if (gloss_mc._visible == false) {
            if (answerkey_arr[_currentframe] == ansSelected) {
                trace("Correct");
                score_int = score_int+1;//add one to the score count
                nextFrame();// go to next frame
            } else {
                trace("Incorrect!");
                // show the gloss
                gloss_mc._visible = true;
                gloss_mc.gloss_txt.text = glosskey_arr[_currentframe];// insert gloss from the array
                // end if statement
                trace("Score is now "+score_int);
    }// end of function

    Try this
    Name the dynamic text box in var not at Instance name
    You will find it in properties panel .By selecting the dynamic text field you will have some properties like var,single line ....ect
    or
    Try this one
    this is your code : score_txt.text = score_int;
    try this :score_txt = score_txt+1;
    where  score_txt is the instance name or the var name you are assigning to the dynamic text field where you will display the score.
    Note: Change all of the dynamic text field name "score_int" in the script in to score_txt ,Because you have changed the dynamic text field to score_txt at the beginig of the script also you have score_int = 0.change heare also.
    If your problem is solved mark this as Answered

  • How do I removing a specific item from an Array?

    Hi there.
    I am having an array of movieclips and when my circle(controlled with the keyboard) hitTests true with one of the movieclips inside that array i want to remove that movieclip from the array so when i hitTest it again it returns false (I hitTest using a "for in" with that array).
    How do i remove a specific item from within an array?
    Can someone help me? Thanks a lot.

    i haven't noticed anyone showing deference because of the points.  in fact, i've seen some people (a minority, to be sure) be just obnoxious about it.  i never encountered that before:  some people feel they have power because they can dole out points.
    but overall i agree with you:  the loss of the list of threads i am participating in, along with the most recent posters name, is a significant drawback of the new forums.  and there's nothing new in these forums that offsets that drawback.
    in addition, i think we've lost way more than 1/2 the older threads.  that's a lot of information that's no longer available.

  • How do I count occurances in an array

    I have a 2D array of strings and I want to count the number of times a particular word occurs in the array. I have been able to isolate the column that contains the string I want to count but I can't seem to get the code to actually count how many times that word shows up.
    Any ideas? Code attached.
    Tay
    Message Edited by slipstick on 04-22-2008 11:34 AM
    Attachments:
    totalizer.vi ‏21 KB

    Here is a quick example, unfortunately it relies on the user being able to correctly enter the word to search for.
    Cheers
    Message Edited by jmcbee on 04-22-2008 10:43 AM
    CLA, CLED, CTD,CPI, LabVIEW Champion
    Platinum Alliance Partner
    Senior Engineer
    Using LV 2013, 2012
    Don't forget Kudos for Good Answers, and Mark a solution if your problem is solved.
    Attachments:
    Count Word.PNG ‏10 KB

  • Retrieve Multiple items using the loop

    Hi All,
    I m using loop for insert the values in the items . The code I used for insertioin is like this :
    DECLARE
    l_pi_val        NUMBER;
    l_count         NUMBER := 0;
    l_role_count   NUMBER := 0;
    BEGIN
        BEGIN
            SELECT count(*)
            INTO   l_count
            FROM   XXORA_SPO_ADDITIONAL_ROLES
            WHERE  spo_number = :P3_SPONSOR_NUMBER;
            EXCEPTION
              WHEN OTHERS THEN
                l_count := 0;
                htp.p('Error in XXORA_SPO_ADDITIONAL_ROLES count - '||:P3_SPONSOR_NUMBER||'-'||SQLERRM);
        END;
        IF l_count = 0 THEN
            BEGIN
                      FOR i IN 1..10
                      LOOP
                            BEGIN
                            IF v('P3_ROLE_'||i) != 'SELECT' THEN
                                    HTP.P('Inside IF');
                                    BEGIN
                                    INSERT INTO XXORA_SPO_ADDITIONAL_ROLES
                                    VALUES( :P3_SPONSOR_NUMBER
                                           , v('P3_ROLE_'||i)
                                           , v('P3_CONTACT_'||i)
                                           , v('P3_DEPT_DIV_'||i)
                                           , v('P3_ROLLNO_'||i) );
                                     HTP.P(v('P3_CONTACT_'||i));
                                     HTP.P(v('P3_DEPT_DIV_'||i));
                                     HTP.P(v('P3_ROLLNO_'||i));
                                    EXCEPTION
                                    WHEN OTHERS THEN
                                        htp.p('Error in Inside Loop in insert into Additional Role - '||i||'-'||SQLERRM);
                                    END;
                            END IF;
                            EXCEPTION
                              WHEN OTHERS THEN
                                 htp.p('Error in FOR LOOP 1 Additional Role - '||i||'-'||SQLERRM);
                            END;
                      END LOOP;         
                      EXCEPTION
                      WHEN OTHERS THEN
                          htp.p('Error outside the loop in insert into Additional Role - '||:P3_SPONSOR_NUMBER||'-'||SQLERRM);
              END;
       ELSE
              BEGIN
                      FOR i in 1..10
                      LOOP
                          BEGIN
                              SELECT count(*)
                              INTO   l_role_count
                              FROM   XXORA_SPO_ADDITIONAL_ROLES
                              WHERE  spo_number = :P3_SPONSOR_NUMBER
                              AND   ROLE_NO    = v('P3_ROLLNO_'||i);
                              EXCEPTION
                                WHEN OTHERS THEN
                                  l_count := 0;
                                  htp.p('Error in XXORA_SPO_ADDITIONAL_ROLES role count - '||:P3_SPONSOR_NUMBER||'-'||SQLERRM);
                          END;
                          IF l_role_count <> 0 THEN
                              IF v('P3_ROLE_'||i) <> 'SELECT' THEN
                                   BEGIN
                                       UPDATE XXORA_SPO_ADDITIONAL_ROLES
                                       SET  ROLE        = v('P3_ROLE_'||i)
                                           , CONTACT_NAME  = v('P3_CONTACT_'||i)
                                           , DEPT_DIV_NAME = v('P3_DEPT_DIV_'||i)
                                       WHERE SPO_NUMBER = :P3_SPONSOR_NUMBER
                                       AND   ROLE_NO    = v('P3_ROLLNO_'||i);
                                       EXCEPTION
                                       WHEN OTHERS THEN
                                            htp.p('Error in Update inside loop into Additional roles  - '||:P3_SPONSOR_NUMBER||'-'||SQLERRM);
                                   END;
                               ELSE
                                   BEGIN
                                       DELETE FROM XXORA_SPO_ADDITIONAL_ROLES
                                       WHERE ROLE_NO  = v('P3_ROLLNO_'||i)
                                       AND SPO_NUMBER = :P3_SPONSOR_NUMBER;
                                       EXCEPTION
                                       WHEN OTHERS THEN
                                            htp.p('Error in Inside delete loop into Additional roles  - '||:P3_SPONSOR_NUMBER||'-'||SQLERRM);                              
                                   END;
                               END IF;
                          ELSE
                              IF v('P3_ROLE_'||i) != 'SELECT' THEN
                                      BEGIN
                                      INSERT INTO XXORA_SPO_ADDITIONAL_ROLES
                                      VALUES( :P3_SPONSOR_NUMBER
                                             , v('P3_ROLE_'||i)
                                             , v('P3_CONTACT_'||i)
                                             , v('P3_DEPT_DIV_'||i)
                                             , v('P3_ROLLNO_'||i) );
                                       HTP.P(v('P3_CONTACT_'||i));
                                       HTP.P(v('P3_DEPT_DIV_'||i));
                                       HTP.P(v('P3_ROLLNO_'||i));
                                      EXCEPTION
                                      WHEN OTHERS THEN
                                          htp.p('Error in Inside Loop in insert into Additional Role - '||i||'-'||SQLERRM);
                                      END;
                              END IF;                       
                          END IF;                          
                      END LOOP;
                EXCEPTION
                         WHEN OTHERS THEN
                             htp.p('Error in Update outside loop into Additional Roles - '||:P3_SPONSOR_NUMBER||'-'||SQLERRM);
              END;        
        END IF;
        COMMIT;
    END;Now what i want is to retrieve the values from the database and keep the values in the respective fields when i am loading the page using a primary key, i need to fetch the data from the database.

    Not in association Johan no.
    You can have one "Family" login they all use to log in but it will kick one out if the other logs in and of course, multiple people sharing the same login increases the security risk.
    You can only set one owner as well.

  • How can i check to see if an object is already in the array list?

    while (res.next()) {
                    Schedule schedule = new Schedule();
                    customerName = res.getString("CUSTOMERNAME");
                    schedule.setCustomerName(customerName);
                    magName = res.getString("MAGNAME");
                    schedule.setMagName(magName);
                    System.out.println("NAME: " + customerName);
                    System.out.println("MAGNAME: " + magName);
                    if(!scheduleListH.contains(schedule))  //this won't work
                        scheduleListH.add(schedule);
                }schedule object has 2 fields, customerName and MagName;
    Basically i want to say, IF the scheudleList (which is an array list) contains an object schedule that has the same customerName and MagName as any of the objects in the array list, don't readd the object.
    ANy help would be great!

    Thanks!
    Oops I forogt I could use the .contains, i also tried that but still no luck.
    There is no compiler error but here is an example of the output:
    Populating scheudle list for HOLIDAY selection data structure: 
    NAME: Cory
    MAGNAME: Merlin
    NAME: Brandon
    MAGNAME: Gondorf
    NAME: Chris
    MAGNAME: Houdini
    NAME: Lokie
    MAGNAME: Blaine
    Sample SCHEDUEL H [Cory          Merlin, Brandon          Gondorf, Chris          Houdini, Lokie          Blaine]As you can see, There are 4 objects in the array list:
    Cory Merlin
    Brandon Gondorf
    Chris Houdini
    Lokie BLaine
    Now this function is called everytime the user choses a new item in a combo box.
    So if they go back to the previous selection, Holiday's, it shouldn't read add all the orginal things.
    But if I go up and select the same item in the combo box it changes whats in the array list to the following:
    Populating scheudle list for HOLIDAY selection data structure: 
    NAME: Cory
    MAGNAME: Merlin
    NAME: Brandon
    MAGNAME: Gondorf
    NAME: Chris
    MAGNAME: Houdini
    NAME: Lokie
    MAGNAME: Blaine
    Sample SCHEDUEL H [Cory          Merlin, Brandon          Gondorf, Chris          Houdini, Lokie          Blaine, Cory          Merlin, Brandon          Gondorf, Chris          Houdini, Lokie          Blaine]Here's my whole function if your interested and where I call it:
        void populateSchedule(String holiday) {
            Statement sta = null;
            Connection connection6 = null;
            try {
                connection6 = DriverManager.getConnection(URL, USERNAME, PASSWORD);
                sta = connection6.createStatement();
                //getting the list of magicians from the selected holiday to see if any are free
                ResultSet res = sta.executeQuery(
                        "SELECT CUSTOMERNAME, MAGNAME FROM SCHEDULE WHERE HOLIDAYNAME = '" + holiday + "'");
                String customerName = " ";
                String magName = " ";
                System.out.println("Populating scheudle list for HOLIDAY selection data structure:  ");
                //this is where I add the waiting list objects to the array that will later be used
                //to print out and shown to the user when they select the waiting list status
                while (res.next()) {
                    Schedule schedule = new Schedule();
                    customerName = res.getString("CUSTOMERNAME");
                    schedule.setCustomerName(customerName);
                    magName = res.getString("MAGNAME");
                    schedule.setMagName(magName);
                    System.out.println("NAME: " + customerName);
                    System.out.println("MAGNAME: " + magName);
                   if(!scheduleListH.contains(schedule))
                       scheduleListH.add(schedule);
                System.out.println("Sample SCHEDUEL H " +   scheduleListH);
            } catch (SQLException ex) {
                System.out.println(ex);
                ex.printStackTrace();
            } finally {
                try {
                    sta.close();
                    connection6.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
    //this is where i call in the GUI
        private void specStatusComboBoxActionPerformed(java.awt.event.ActionEvent evt) {                                                  
            // TODO add your handling code here:
            String selectedItem = (String)specStatusComboBox.getSelectedItem();
            String groupSelectedItem = (String) groupStatusComboBox.getSelectedItem();
            if(groupSelectedItem.equals("Holidays"))
                //get customer name and magician name from the Scheduel table
                //use selectedItem (it will be a holiday name)
                //magicDB.clearScheduleHList();
                magicDB.populateSchedule(selectedItem);
                ArrayList<Schedule> tempScheduleList = magicDB.getScheduleHListCopy();
                outputTextArea.setText(" ");
                outputTextArea.setText("CUSTOMER NAME" +"\t\t" + "MAGICIAN NAME" + "\n");
                for(int i = 0; i < tempScheduleList.size(); i++)
                    outputTextArea.append(tempScheduleList.get(i).toString() + "\n");
        }   I'll reward the duke stars anyways because you have been a great help either way!

  • How to update a chart when the array is updated

    Hi I am using an array to populate a chart in FB3 and having trouble updating the chart when the array is updated.
    Chart
             <mx:Label id="archiveTitle" x="10" y="10" text="Current Archive " fontSize="14" fontWeight="bold"/>
             <mx:PieChart id="chart" height="130" width="300" color="0x323232"
                showDataTips="false" dataProvider="{ratingAC}"  y="22">
                 <mx:series>
                    <mx:PieSeries field="Rating"/>
                </mx:series>
            </mx:PieChart>
    Array + Vars
             [Bindable]
             public var newsDB:ArrayCollection = mx.core.Application.application.newsDB as ArrayCollection;
             [Bindable]
             private var positive:int = 1;
             [Bindable]
             private var neutral:int = 0;
             [Bindable]
             private var negative:int = 0;
             [Bindable]
             private var ratingAC:ArrayCollection = new ArrayCollection([
             { Rating: 1 },  // no data
             { Rating: positive }, // [0] positive
             { Rating: neutral }, // [1] neutral
             { Rating: negative }  // [2] negative
            private function init():void{
                   buildChart();
                   newsDB.addEventListener(CollectionEvent.COLLECTION_CHANGE, test);
                   newsDB.addEventListener(CollectionEvent.COLLECTION_CHANGE, buildChart);
            private function test(e:CollectionEvent):void{
                 trace("array changed");
                 positive = 20
            private function buildChart(e:CollectionEvent=null):void{
                 for(var i:int; i<newsDB.length; i++){
                      if(newsDB[i].rateItem == 0){
                           trace(positive);
                           positive += 1;
                           //ratingAC.setItemAt(positive,0);
                           trace(positive);
                      if(newsDB[i].rateItem == 1){
                           neutral += 1;
                      if(newsDB[i].rateItem == 2){
                           negative += 1;

    Sorry, in my app I have an ArrayCollection of items from a news feed that the user has deemed important, and given each item a rating. The For loop will loop through the "newsDB" array and set the var accordingly (positive, negative, neutral). The variables are what is populating the arrayCollection (ratingAC). How would I either a) bind the variables to the ArrayCollection so that it updates when one has changed, or b) update the specific index in the array collection. When debugging, i notice that the variables are updating, but the arrayCollection is not.
    Thanks in advance!

  • Count consecutive days in array

    Hi,
    I'm looking for an algorithm to count consecutive days in array, but i don't find one.
    for example, if i have this array.
    2009/07/01
    2009/07/02
    2009/07/03
    2009/07/06
    2009/07/08
    2009/07/09
    2009/07/10
    2009/07/11
    The result be
    3
    1
    4
    Anyone have one?
    Thanks for all.

    jverd wrote:
    kajbj wrote:
    It's a fairly specialist algorithm so you are unlikely to find someone to post a solution. By just keeping a reference to the previous date, it is easy to iterate though the list counting consecutive dates.I think the trick to making this algorithm sucessful is to make sure that when you change months your algorithm doesn't set consec_days to 0 Why not?Presumably he's talking about this case:
    7/31
    8/1
    and not this case
    7/1
    8/1
    So he really should have said, "...when you increment month by one, or from 12 to 1, and the day went from the last day of the old month to 1, don't set consec_days to 0"Ok. I would use the Calendar class and SimpleDateFormat. The tricky part would otherwise be to keep track of days per month, and leap year.

  • How remove duplication in the array

    import java.util.*;
    public class stringlength{
         public static void main(String[] args){
              String p = "i love java very much.but i like it";
              String t = "i love java very much.but i like it";
              String[] sentence1 = p.split("\\.");
              String[] sentence2 = t.split("\\.");
              String[] EachLine1;
              String[] EachLine2;     
    //*******Begin break the paragraph into line p and t****************
              for(int line1_p = 0 ; line1_p < sentence1.length ; line1_p++){
                        EachLine1 = sentence1[line1_p].split(" ");          
                   for(int line2_t = 0 ; line2_t < sentence2.length ; line2_t++){
                        EachLine2 = sentence2[line2_t].split(" ");
              //************End of break line*************************************
              //************Begin compare each word********************************
                        for(int word_p = 0 ; word_p < EachLine1.length ; word_p++){          
                             for(int word_t = 0 ; word_t < EachLine2.length ; word_t++){
                                  if(EachLine2[word_t].equals(EachLine1[word_p])){
                                       System.out.println(EachLine1[word_p]);
                             if(count>6){     // set the size that want to match
                                                 cost++;
              //*************End of compare*****************************************
    the above is my coding.
    well i wan compare the 2 string..then if found matched...print out the match word.
    from the comparison, it will create duplication during the matching.
    so i wan remove all the duplication word by only print out the match result.
    thx guys.....:)

    well i found out the solution from the example already.
    but that one is for single array...
    now i want to compare 2 string together but when i found the matched word...it cannot remove the duplication words..
    anyone can help me to solve this problem?
    it is very urgent..!!
    import java.util.*;
    public class FindDups {
        public static void main(String args[]) {
             String a ="i came i saw i left left left";
             String b ="i came i saw i left left left";
             String[] c=a.split(" ");
             String[] d=a.split(" ");
             for(int i=0;i<c.length;i++){
                  for(int j=0;j<d.length;j++){
                       if(c.equals(d[j])){
                   String[] e=d[j].split(" ");
                   ArrayList aList;
                        aList = new ArrayList( Arrays.asList(e ) );
              HashSet s = new HashSet( aList ); // create a HashSet     
              System.out.println(" distinct words detected: "+s);

Maybe you are looking for

  • Unable to convert the sender service ABC_Service to an ALE logical system

    Hi, I have a JMS (Party) --> PI --> IDOC scenario. Party: ABC_Party Service: ABC_Service I am getting the error Unable to convert the sender service ABC_Service to an ALE logical system when I test the scenario using RWB -> Component Monitoring -> In

  • Reg: UDF for removing values after decimals

    HI,   Please help me on the below issue,   I need an UDF for the follwing requirement, as my input value is 12354.12354875 then the result will be like 12345.123, After deceimal it should get only 3 values. Please help me points will be awarded. Edit

  • Auto_increment option not appearing in phpmyadmin

    I thought i'd learn how this whole LAMP thing works, so i set up an Arch server and installed the necessary stuff i.e Apache, PHP, mysql and phpmyadmin. However, whenever i'm creating a table in a database using phpmyadmin, there's no option to auto_

  • Patches of 4.7 and 5.0

    hi Please let me know the pathces of 4.7 and 5.0 in FI-CO.  What are the major paches are happining in 5.0 thanx sri

  • Web Client Doesn't Display Address Book in 9.0.4

    Is there any way to get the Address Book feature enabled for users in the Web client of Calendar in version 9.0.4? If this feature isn't supported yet, will it be in the next release?