Results 1 to 2 of 2
  1. #1
    jwl
    jwl is offline Member
    Join Date
    Jul 2012
    Posts
    93
    Rep Power
    0

    Default count array data less than number being compared to

    I have an array with specified data int[] nums = {5,2,1,4,3};
    what I need to do is take the smaller slot i. e. 0 < 4 and count the values in the slots bigger (0 < 1 & 2 & 3 & 4) that have a greater value than the value of the number in the smaller slot. since 5 is greater than 2,1,4,3 the count will be 4 for that comparison and for slot 2 the count will be 1 since the only number after slot 1/nums[1] that is smaller than 2 is 1 and so on.

    Here is what I have so far:

    Java Code:
     public void CountOutOfOrderPairs(int[] nums) { //return int
            nums = {5,2,1,4,3}; 
            int i, j = nums[4], count = 0;
            for (i = 0; i < nums.length; i++) {
                if (nums[i] > j)
                     count++;
                    System.out.println(count + "after count");
            }
        }

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: count array data less than number being compared to

    Ok, and what is your question?

Similar Threads

  1. Count number of rows
    By Kenan_89 in forum Advanced Java
    Replies: 11
    Last Post: 01-26-2012, 12:52 PM
  2. Replies: 8
    Last Post: 01-21-2012, 01:14 AM
  3. day number count
    By droidus in forum New To Java
    Replies: 14
    Last Post: 03-23-2011, 10:15 PM
  4. Replies: 23
    Last Post: 09-07-2010, 08:12 PM
  5. Array count number Occurances
    By gwithey in forum New To Java
    Replies: 2
    Last Post: 04-17-2009, 08:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •