Results 1 to 2 of 2
- 11-14-2012, 09:18 PM #1
Member
- Join Date
- Jul 2012
- Posts
- 93
- Rep Power
- 0
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"); } }
- 11-14-2012, 10:32 PM #2
Similar Threads
-
Count number of rows
By Kenan_89 in forum Advanced JavaReplies: 11Last Post: 01-26-2012, 12:52 PM -
Easy Question! Print out file, count number of lines, number of spaces w/ Scanner
By LogicalOutlier in forum New To JavaReplies: 8Last Post: 01-21-2012, 01:14 AM -
day number count
By droidus in forum New To JavaReplies: 14Last Post: 03-23-2011, 10:15 PM -
Variable of an object in an array compared to an element of another array?
By asmodean in forum New To JavaReplies: 23Last Post: 09-07-2010, 08:12 PM -
Array count number Occurances
By gwithey in forum New To JavaReplies: 2Last Post: 04-17-2009, 08:34 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks