Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Java N-ary Counter

Reply
Thread Tools

Java N-ary Counter

 
 
Hanky Sjafrie
Guest
Posts: n/a
 
      09-19-2003
Greetings,

I need help on implementing a N-ary counter, which iterates from zero
to the maximum value allowed for each column. The maximum value of
n-th column should corresponds to the n-th value of the input array,
for example:

int[] inputArray ={2,1,3};

The output should be stored in a double array:
int[][] outputArray = new int[2*1*3][inputArray.length];

which has the values like these:
outputArray[0][] = {0,0,0}
outputArray[1][] = {0,0,1}
outputArray[2][] = {0,0,2}
outputArray[3][] = {1,0,0}
outputArray[4][] = {1,0,1}
outputArray[5][] = {1,0,2}

Probably a recursive will do, but I'm still out of luck...
Any help would be greatly appreciated. Thanks in advance!

Regards,

Hanky
 
Reply With Quote
 
 
 
 
pete kirkham
Guest
Posts: n/a
 
      09-20-2003
Hanky Sjafrie wrote:
> I need help on implementing a N-ary counter


> The output should be stored in a double array:

By which you mean an integer array of rank 2.

Assuming this is probably homework, you need to look at the 'modulus'
operator % (strictly the remainder operator, as the behaviour differs
for negative integers), and think carrying the overflow from one digit
to the next. That can be done quite easily iteratively, by a loop that
starts at the least significant digit and increments until the most
sig'nt digit is reached, or of course recursively if you really want to.


Pete

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Page File counter and Private Bytes Counter George2 C++ 1 01-31-2008 09:27 AM
Reset network creation counter J.H. Holliday Wireless Networking 4 06-11-2005 08:09 PM
Session("counter") vs. ViewState("counter")...a newbie question The Eeediot ASP .Net 3 12-22-2004 09:31 PM
Java Applet counter doesn't display correctly Dick Stouffer Firefox 8 10-05-2004 04:52 PM
can I do such a simplest counter in VHDL? walala VHDL 3 09-14-2003 08:05 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57