hi everone,
i am trying to write a function called shiftDown.
This function needs to move the contents of an array one place back .
ex. int[] intarray = new int[4]
intarray[0] = 1;
intarray[1] = 2;
intarray[2] = 3;
intarray[3] = 4;
then i want to use the function and i must have the following: intarray[0]
must then be 2
intarray[1] must be 3
intarray[2] must be 4
and intarray[3] must be 1
i am working on this for days now and still can't figure it out this is
what i allready have but it doesn't work
public void shiftDown() {
for (int i = 0; i < lengte2.length; i++) {
if ( lengte2[i] == lengte2.length) {
lengte2[i] = lengte2[0];
lengte2[i] = lengte2[i + 1];
}
}
}
lengte2 is my array.
TIA
Tommaz
|
|
0
|
|
|
|
Reply
|
tommaz (8)
|
9/28/2003 3:47:15 PM |
|
Tom Wouters <Tommaz@pandora.be> scribbled the following:
> hi everone,
> i am trying to write a function called shiftDown.
> This function needs to move the contents of an array one place back .
> ex. int[] intarray = new int[4]
> intarray[0] = 1;
> intarray[1] = 2;
> intarray[2] = 3;
> intarray[3] = 4;
> then i want to use the function and i must have the following: intarray[0]
> must then be 2
> intarray[1] must be 3
> intarray[2] must be 4
> and intarray[3] must be 1
> i am working on this for days now and still can't figure it out this is
> what i allready have but it doesn't work
> public void shiftDown() {
> for (int i = 0; i < lengte2.length; i++) {
> if ( lengte2[i] == lengte2.length) {
> lengte2[i] = lengte2[0];
> lengte2[i] = lengte2[i + 1];
> }
> }
> }
> lengte2 is my array.
Here's an algorithm for you. Put lengte2[0] into some temporary variable.
Then for all i in 1 to lengte[2].length-1, put lengte2[i] into
lengte2[i-1]. Finally put the temporary variable into
lengte2[lengte2.length-1].
Just write this algorithm out in Java and you've solved your homework.
--
/-- Joona Palaste (palaste@cc.helsinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"Remember: There are only three kinds of people - those who can count and those
who can't."
- Vampyra
|
|
0
|
|
|
|
Reply
|
palaste (2323)
|
9/28/2003 3:54:31 PM
|
|
"Joona I Palaste" <palaste@cc.helsinki.fi> schreef in bericht
news:bl707n$quv$1@oravannahka.helsinki.fi...
> Tom Wouters <Tommaz@pandora.be> scribbled the following:
> > hi everone,
>
> > i am trying to write a function called shiftDown.
> > This function needs to move the contents of an array one place back .
> > ex. int[] intarray = new int[4]
>
> > intarray[0] = 1;
> > intarray[1] = 2;
> > intarray[2] = 3;
> > intarray[3] = 4;
>
> > then i want to use the function and i must have the following:
intarray[0]
> > must then be 2
> > intarray[1] must be 3
> > intarray[2] must be 4
> > and intarray[3] must be 1
>
> > i am working on this for days now and still can't figure it out this
is
> > what i allready have but it doesn't work
>
> > public void shiftDown() {
> > for (int i = 0; i < lengte2.length; i++) {
> > if ( lengte2[i] == lengte2.length) {
> > lengte2[i] = lengte2[0];
> > lengte2[i] = lengte2[i + 1];
> > }
> > }
> > }
>
> > lengte2 is my array.
>
> Here's an algorithm for you. Put lengte2[0] into some temporary variable.
> Then for all i in 1 to lengte[2].length-1, put lengte2[i] into
> lengte2[i-1]. Finally put the temporary variable into
> lengte2[lengte2.length-1].
>
> Just write this algorithm out in Java and you've solved your homework.
ok but i am sorry to say this but I don't get it :(
can you explain it a little easyer
>
> --
> /-- Joona Palaste (palaste@cc.helsinki.fi) ---------------------------\
> | Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
> | http://www.helsinki.fi/~palaste W++ B OP+ |
> \----------------------------------------- Finland rules! ------------/
> "Remember: There are only three kinds of people - those who can count and
those
> who can't."
> - Vampyra
|
|
0
|
|
|
|
Reply
|
tommaz (8)
|
9/28/2003 4:03:38 PM
|
|
"Joona I Palaste" <palaste@cc.helsinki.fi> wrote in message news:bl707n$quv$1@oravannahka.helsinki.fi...
> Tom Wouters <Tommaz@pandora.be> scribbled the following:
> > hi everone,
>
> > i am trying to write a function called shiftDown.
> > This function needs to move the contents of an array one place back .
> > ex. int[] intarray = new int[4]
>
> > intarray[0] = 1;
> > intarray[1] = 2;
> > intarray[2] = 3;
> > intarray[3] = 4;
>
> > then i want to use the function and i must have the following: intarray[0]
> > must then be 2
> > intarray[1] must be 3
> > intarray[2] must be 4
> > and intarray[3] must be 1
>
> > i am working on this for days now and still can't figure it out this is
> > what i allready have but it doesn't work
>
> > public void shiftDown() {
> > for (int i = 0; i < lengte2.length; i++) {
> > if ( lengte2[i] == lengte2.length) {
> > lengte2[i] = lengte2[0];
> > lengte2[i] = lengte2[i + 1];
> > }
> > }
> > }
>
> > lengte2 is my array.
>
> Here's an algorithm for you. Put lengte2[0] into some temporary variable.
> Then for all i in 1 to lengte[2].length-1, put lengte2[i] into
> lengte2[i-1]. Finally put the temporary variable into
> lengte2[lengte2.length-1].
>
> Just write this algorithm out in Java and you've solved your homework.
This is so C-ish (and I love it) but to the OP I want to say two things:
1) Have a look at System.arraycopy() (if you like Joona's solution);
2) Have a look at the ArrayList class.
kind regards,
Jos
|
|
0
|
|
|
|
Reply
|
j.a.horsmeier (104)
|
9/28/2003 4:14:30 PM
|
|
On Sun, 28 Sep 2003 15:47:15 +0000, Tom Wouters wrote:
> public void shiftDown() {
> for (int i = 0; i < lengte2.length; i++) {
> if ( lengte2[i] == lengte2.length) {
> lengte2[i] = lengte2[0];
> lengte2[i] = lengte2[i + 1];
> }
> }
> }
Looks like a Computer Science 101 homework problem.
You may be a student, so, I am not going to give you code.
But, here is an explanation of one possible solution:
First, you copy the 0th element into a temporary variable.
Next, you want to loop from the 0th element all the way
to the (n-1)th element and copy the next element's value
into the current element.
Last, you copy the value of the temporary variable into the
nth element.
Do you understand this solution and if it will work?
If so, try to write the code yourself.
Good luck.
|
|
0
|
|
|
|
Reply
|
no.spam4136 (32)
|
9/28/2003 4:22:06 PM
|
|
Tom Wouters wrote:
>
> "Joona I Palaste" <palaste@cc.helsinki.fi> schreef in bericht
> news:bl707n$quv$1@oravannahka.helsinki.fi...
>> Tom Wouters <Tommaz@pandora.be> scribbled the following:
>> > hi everone,
>>
>> > i am trying to write a function called shiftDown.
>> > This function needs to move the contents of an array one place back .
>> > ex. int[] intarray = new int[4]
>>
>> > intarray[0] = 1;
>> > intarray[1] = 2;
>> > intarray[2] = 3;
>> > intarray[3] = 4;
>>
>> > then i want to use the function and i must have the following:
> intarray[0]
>> > must then be 2
>> > intarray[1] must be 3
>> > intarray[2] must be 4
>> > and intarray[3] must be 1
>>
>> > i am working on this for days now and still can't figure it out this
> is
>> > what i allready have but it doesn't work
>>
>> > public void shiftDown() {
>> > for (int i = 0; i < lengte2.length; i++) {
>> > if ( lengte2[i] == lengte2.length) {
>> > lengte2[i] = lengte2[0];
>> > lengte2[i] = lengte2[i + 1];
>> > }
>> > }
>> > }
>>
>> > lengte2 is my array.
>>
>> Here's an algorithm for you. Put lengte2[0] into some temporary variable.
>> Then for all i in 1 to lengte[2].length-1, put lengte2[i] into
>> lengte2[i-1]. Finally put the temporary variable into
>> lengte2[lengte2.length-1].
>>
>> Just write this algorithm out in Java and you've solved your homework.
>
>
> ok but i am sorry to say this but I don't get it :(
> can you explain it a little easyer
>>
>> --
>> /-- Joona Palaste (palaste@cc.helsinki.fi) ---------------------------\
>> | Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
>> | http://www.helsinki.fi/~palaste W++ B OP+ |
>> \----------------------------------------- Finland rules! ------------/
>> "Remember: There are only three kinds of people - those who can count and
> those
>> who can't."
>> - Vampyra
In simple English : put the first element of your array (length2[0] ) into
some temp. variable like ( int temp = length2[0] ), and then do the
following :
For all i in 1 to (length2.length-1), length2[i-1] is set to length2[i].
When this loop finishes, put the temp variable (temp) back into
length2[length2.length-1].
Sorry, but simpler then this it doesn't come.
Brgds, Herman
--
Suse Linux Professional 8.1 on Athlon 1.1 Ghz 512 Mb
Anti Spam = remove the "dot" and the "at"
Registered Linux User #264690
|
|
0
|
|
|
|
Reply
|
timmermansdot.hermanat (6)
|
9/28/2003 4:22:14 PM
|
|
Dank u ik denk dat u ofwel nederlands of belgisch bent kan u misschien
even uitleggen in nederlands aub.
alvast bedankt
ps dit snap ik niet zo goed: For all i in 1 to (length2.length-1),
length2[i-1] is set to length2[i].
"Herman Timmermans" <timmermansdot.hermanat@skynet.be> schreef in bericht
news:3f770a98$0$31726$ba620e4c@reader1.news.skynet.be...
> Tom Wouters wrote:
>
> >
> > "Joona I Palaste" <palaste@cc.helsinki.fi> schreef in bericht
> > news:bl707n$quv$1@oravannahka.helsinki.fi...
> >> Tom Wouters <Tommaz@pandora.be> scribbled the following:
> >> > hi everone,
> >>
> >> > i am trying to write a function called shiftDown.
> >> > This function needs to move the contents of an array one place back .
> >> > ex. int[] intarray = new int[4]
> >>
> >> > intarray[0] = 1;
> >> > intarray[1] = 2;
> >> > intarray[2] = 3;
> >> > intarray[3] = 4;
> >>
> >> > then i want to use the function and i must have the following:
> > intarray[0]
> >> > must then be 2
> >> > intarray[1] must be 3
> >> > intarray[2] must be 4
> >> > and intarray[3] must be 1
> >>
> >> > i am working on this for days now and still can't figure it out
this
> > is
> >> > what i allready have but it doesn't work
> >>
> >> > public void shiftDown() {
> >> > for (int i = 0; i < lengte2.length; i++) {
> >> > if ( lengte2[i] == lengte2.length) {
> >> > lengte2[i] = lengte2[0];
> >> > lengte2[i] = lengte2[i + 1];
> >> > }
> >> > }
> >> > }
> >>
> >> > lengte2 is my array.
> >>
> >> Here's an algorithm for you. Put lengte2[0] into some temporary
variable.
> >> Then for all i in 1 to lengte[2].length-1, put lengte2[i] into
> >> lengte2[i-1]. Finally put the temporary variable into
> >> lengte2[lengte2.length-1].
> >>
> >> Just write this algorithm out in Java and you've solved your homework.
> >
> >
> > ok but i am sorry to say this but I don't get it :(
> > can you explain it a little easyer
> >>
> >> --
> >> /-- Joona Palaste (palaste@cc.helsinki.fi) ---------------------------\
> >> | Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
> >> | http://www.helsinki.fi/~palaste W++ B OP+ |
> >> \----------------------------------------- Finland rules! ------------/
> >> "Remember: There are only three kinds of people - those who can count
and
> > those
> >> who can't."
> >> - Vampyra
> In simple English : put the first element of your array (length2[0] ) into
> some temp. variable like ( int temp = length2[0] ), and then do the
> following :
> For all i in 1 to (length2.length-1), length2[i-1] is set to length2[i].
> When this loop finishes, put the temp variable (temp) back into
> length2[length2.length-1].
> Sorry, but simpler then this it doesn't come.
> Brgds, Herman
>
> --
> Suse Linux Professional 8.1 on Athlon 1.1 Ghz 512 Mb
> Anti Spam = remove the "dot" and the "at"
> Registered Linux User #264690
|
|
0
|
|
|
|
Reply
|
tommaz (8)
|
9/28/2003 4:30:36 PM
|
|
Tom Wouters wrote:
As a matter of exception I'll reply in Dutch for you - sorry for all the
others ;-)
Indien je array bv? 5 elementen heeft [0..4] dan maak je een For loop
constructie (zoals in C) in Java (for i=1 to (5-1) maw 4) en dan zet je
length2[i-1]=length2[i] (bv. wanneer je in de loop komt, en i dus 1 is,
length2[1-1] (is dus length2[0]) = length2[1], en zo verder tot de loop
stopt.
Mvg, Herman
> Dank u ik denk dat u ofwel nederlands of belgisch bent kan u misschien
> even uitleggen in nederlands aub.
>
> alvast bedankt
>
> ps dit snap ik niet zo goed: For all i in 1 to (length2.length-1),
> length2[i-1] is set to length2[i].
>
> "Herman Timmermans" <timmermansdot.hermanat@skynet.be> schreef in bericht
> news:3f770a98$0$31726$ba620e4c@reader1.news.skynet.be...
>> Tom Wouters wrote:
>>
>> >
>> > "Joona I Palaste" <palaste@cc.helsinki.fi> schreef in bericht
>> > news:bl707n$quv$1@oravannahka.helsinki.fi...
>> >> Tom Wouters <Tommaz@pandora.be> scribbled the following:
>> >> > hi everone,
>> >>
>> >> > i am trying to write a function called shiftDown.
>> >> > This function needs to move the contents of an array one place back
>> >> > . ex. int[] intarray = new int[4]
>> >>
>> >> > intarray[0] = 1;
>> >> > intarray[1] = 2;
>> >> > intarray[2] = 3;
>> >> > intarray[3] = 4;
>> >>
>> >> > then i want to use the function and i must have the following:
>> > intarray[0]
>> >> > must then be 2
>> >> > intarray[1] must be 3
>> >> > intarray[2] must be 4
>> >> > and intarray[3] must be 1
>> >>
>> >> > i am working on this for days now and still can't figure it out
> this
>> > is
>> >> > what i allready have but it doesn't work
>> >>
>> >> > public void shiftDown() {
>> >> > for (int i = 0; i < lengte2.length; i++) {
>> >> > if ( lengte2[i] == lengte2.length) {
>> >> > lengte2[i] = lengte2[0];
>> >> > lengte2[i] = lengte2[i + 1];
>> >> > }
>> >> > }
>> >> > }
>> >>
>> >> > lengte2 is my array.
>> >>
>> >> Here's an algorithm for you. Put lengte2[0] into some temporary
> variable.
>> >> Then for all i in 1 to lengte[2].length-1, put lengte2[i] into
>> >> lengte2[i-1]. Finally put the temporary variable into
>> >> lengte2[lengte2.length-1].
>> >>
>> >> Just write this algorithm out in Java and you've solved your homework.
>> >
>> >
>> > ok but i am sorry to say this but I don't get it :(
>> > can you explain it a little easyer
>> >>
>> >> --
>> >> /-- Joona Palaste (palaste@cc.helsinki.fi)
>> >> ---------------------------\
>> >> | Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA
>> >> | N+++|
>> >> | http://www.helsinki.fi/~palaste W++ B OP+
>> >> | |
>> >> \----------------------------------------- Finland rules!
>> >> ------------/ "Remember: There are only three kinds of people - those
>> >> who can count
> and
>> > those
>> >> who can't."
>> >> - Vampyra
>> In simple English : put the first element of your array (length2[0] )
>> into some temp. variable like ( int temp = length2[0] ), and then do the
>> following :
>> For all i in 1 to (length2.length-1), length2[i-1] is set to length2[i].
>> When this loop finishes, put the temp variable (temp) back into
>> length2[length2.length-1].
>> Sorry, but simpler then this it doesn't come.
>> Brgds, Herman
>>
>> --
>> Suse Linux Professional 8.1 on Athlon 1.1 Ghz 512 Mb
>> Anti Spam = remove the "dot" and the "at"
>> Registered Linux User #264690
--
Suse Linux Professional 8.1 on Athlon 1.1 Ghz 512 Mb
Anti Spam = remove the "dot" and the "at"
Registered Linux User #264690
|
|
0
|
|
|
|
Reply
|
timmermansdot.hermanat (6)
|
9/28/2003 4:40:48 PM
|
|
Jos A. Horsmeier <j.a.horsmeier@wanadoo.nl> scribbled the following:
> "Joona I Palaste" <palaste@cc.helsinki.fi> wrote in message news:bl707n$quv$1@oravannahka.helsinki.fi...
>> Tom Wouters <Tommaz@pandora.be> scribbled the following:
>> > hi everone,
>>
>> > i am trying to write a function called shiftDown.
>> > This function needs to move the contents of an array one place back .
(snip)
> This is so C-ish (and I love it) but to the OP I want to say two things:
> 1) Have a look at System.arraycopy() (if you like Joona's solution);
> 2) Have a look at the ArrayList class.
Who knows, maybe Tom's professor wants him to give a C-ish solution.
--
/-- Joona Palaste (palaste@cc.helsinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"Make money fast! Don't feed it!"
- Anon
|
|
0
|
|
|
|
Reply
|
palaste (2323)
|
9/28/2003 4:42:08 PM
|
|
Ok i found it out and it worked thanks
but if i want to do this in the other direction(move all the contents of the
arrays one place up instead of down)
then i get an arrayindexoutofboundexception.
I wrote the code like this:
public void shiftUp() {
int temp = lengte2[lengte2.length - 1];
for (int i = 0; i < lengte2.length; i++) {
lengte2[i + 1] = lengte2[i];
}
lengte2[0] = temp;
}
does this means that my for statement keeps on "rolling"?
"Tom Wouters" <Tommaz@pandora.be> schreef in bericht
news:7oDdb.45756$v93.1894515@phobos.telenet-ops.be...
> hi everone,
>
> i am trying to write a function called shiftDown.
> This function needs to move the contents of an array one place back .
> ex. int[] intarray = new int[4]
>
> intarray[0] = 1;
> intarray[1] = 2;
> intarray[2] = 3;
> intarray[3] = 4;
>
> then i want to use the function and i must have the following: intarray[0]
> must then be 2
> intarray[1] must be 3
> intarray[2] must be 4
> and intarray[3] must be 1
>
> i am working on this for days now and still can't figure it out this is
> what i allready have but it doesn't work
>
> public void shiftDown() {
> for (int i = 0; i < lengte2.length; i++) {
> if ( lengte2[i] == lengte2.length) {
> lengte2[i] = lengte2[0];
> lengte2[i] = lengte2[i + 1];
> }
> }
> }
>
> lengte2 is my array.
>
> TIA
>
> Tommaz
>
>
|
|
0
|
|
|
|
Reply
|
tommaz (8)
|
9/28/2003 6:37:31 PM
|
|
On Sun, 28 Sep 2003 18:37:31 GMT, Tom Wouters wrote:
> Ok i found it out and it worked thanks
>
> but if i want to do this in the other direction(move all the
> contents of the arrays one place up instead of down) then i get an
> arrayindexoutofboundexception.
>
> I wrote the code like this:
>
> public void shiftUp() {
> int temp = lengte2[lengte2.length - 1];
> for (int i = 0; i < lengte2.length; i++) {
> lengte2[i + 1] = lengte2[i];
> }
> lengte2[0] = temp;
> }
>
> does this means that my for statement keeps on "rolling"?
No, it means that you need to think more about which array positions
you attempt to access.
Remember that the last position in an array is at length-1.
Your loop only goes to length-1, but you access both positions i and
i+1 on each pass, so you go too far.
/gordon
--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
|
|
0
|
|
|
|
Reply
|
not108 (1060)
|
9/28/2003 6:51:30 PM
|
|
On Sun, 28 Sep 2003 18:37:31 GMT, "Tom Wouters" <Tommaz@pandora.be>
wrote or quoted :
> for (int i = 0; i < lengte2.length; i++) {
> lengte2[i + 1] = lengte2[i];
> }
You are overwriting yourself, and just propagating the [0] element
throughout. To shift up, you must work from the top down. To shift
down you would work from the bottom up.
See http://mindprod.com/jgloss/jcheat.html for how to do a reverse
for.
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
|
|
0
|
|
|
|
Reply
|
roedy4 (532)
|
9/28/2003 7:25:10 PM
|
|
ok now my code is like this but i still get the exception with a -1 after
it. My for is rolling till -1 but i don't know how to fix this.
can someone help me with this
public void shiftUp() {
int temp = lengte2[lengte2.length - 1];
for (int i = lengte2.length - 1; i >= 0; i--) {
lengte2[i - 1] = lengte2[i];
}
lengte2[0] = temp;
}
Tommaz
"Gordon Beaton" <not@for.email> schreef in bericht
news:3f772dac$1@news.wineasy.se...
> On Sun, 28 Sep 2003 18:37:31 GMT, Tom Wouters wrote:
> > Ok i found it out and it worked thanks
> >
> > but if i want to do this in the other direction(move all the
> > contents of the arrays one place up instead of down) then i get an
> > arrayindexoutofboundexception.
> >
> > I wrote the code like this:
> >
> > public void shiftUp() {
> > int temp = lengte2[lengte2.length - 1];
> > for (int i = 0; i < lengte2.length; i++) {
> > lengte2[i + 1] = lengte2[i];
> > }
> > lengte2[0] = temp;
> > }
> >
> > does this means that my for statement keeps on "rolling"?
>
> No, it means that you need to think more about which array positions
> you attempt to access.
>
> Remember that the last position in an array is at length-1.
>
> Your loop only goes to length-1, but you access both positions i and
> i+1 on each pass, so you go too far.
>
> /gordon
>
> --
> [ do not email me copies of your followups ]
> g o r d o n + n e w s @ b a l d e r 1 3 . s e
|
|
0
|
|
|
|
Reply
|
tommaz (8)
|
9/28/2003 9:01:13 PM
|
|
Tom Wouters wrote:
> ok now my code is like this but i still get the exception with a -1 after
> it. My for is rolling till -1 but i don't know how to fix this.
> can someone help me with this
>
> public void shiftUp() {
> int temp = lengte2[lengte2.length - 1];
> for (int i = lengte2.length - 1; i >= 0; i--) {
> lengte2[i - 1] = lengte2[i];
> }
> lengte2[0] = temp;
> }
>
> Tommaz
[knip]
Tom,
it should be for (int i = lengte2.length-1;i>0;i--),
because if i=0, your next statement becomes like this :
length2[0-1] = length2[0] << this gives the error, a negative index into
your array
Brgds, Herman
--
Suse Linux Professional 8.1 on Athlon 1.1 Ghz 512 Mb
Anti Spam = remove the "dot" and the "at"
Registered Linux User #264690
|
|
0
|
|
|
|
Reply
|
timmermansdot.hermanat (6)
|
9/29/2003 5:33:55 AM
|
|
Hello,
i am still working on this project. I am a little bit further now but now i
have to give a parameter to the methode shiftDown so that i can say how many
place it has to shift down. My code is like this but i still get an
arrayindexoutofboundexception. I don't know why because i wrote it down on a
paper and it seems to be right.
public void shiftDown(int hoeveel) {
for (int i = 1; i <= lengte2.length; i++) {
if (lengte2[i + hoeveel - 1]>=lengte2.length){
lengte2[i - 1] = lengte2[i + hoeveel - 1 - lengte2.length];
}else{
lengte2[i - 1] = lengte2[i + hoeveel - 1];
}
}
}
greets Tom
"Tom Wouters" <Tommaz@pandora.be> schreef in bericht
news:7oDdb.45756$v93.1894515@phobos.telenet-ops.be...
> hi everone,
>
> i am trying to write a function called shiftDown.
> This function needs to move the contents of an array one place back .
> ex. int[] intarray = new int[4]
>
> intarray[0] = 1;
> intarray[1] = 2;
> intarray[2] = 3;
> intarray[3] = 4;
>
> then i want to use the function and i must have the following: intarray[0]
> must then be 2
> intarray[1] must be 3
> intarray[2] must be 4
> and intarray[3] must be 1
>
> i am working on this for days now and still can't figure it out this is
> what i allready have but it doesn't work
>
> public void shiftDown() {
> for (int i = 0; i < lengte2.length; i++) {
> if ( lengte2[i] == lengte2.length) {
> lengte2[i] = lengte2[0];
> lengte2[i] = lengte2[i + 1];
> }
> }
> }
>
> lengte2 is my array.
>
> TIA
>
> Tommaz
>
>
|
|
0
|
|
|
|
Reply
|
tommaz (8)
|
9/29/2003 6:54:05 PM
|
|
Tom Wouters wrote:
> Hello,
>
> i am still working on this project. I am a little bit further now but now
> i have to give a parameter to the methode shiftDown so that i can say how
> many place it has to shift down. My code is like this but i still get an
> arrayindexoutofboundexception. I don't know why because i wrote it down on
> a paper and it seems to be right.
>
> public void shiftDown(int hoeveel) {
>
> for (int i = 1; i <= lengte2.length; i++) {
>
> if (lengte2[i + hoeveel - 1]>=lengte2.length){
>
> lengte2[i - 1] = lengte2[i + hoeveel - 1 - lengte2.length];
>
> }else{
>
> lengte2[i - 1] = lengte2[i + hoeveel - 1];
>
> }
>
> }
>
> }
>
>
>
> greets Tom
>
> "Tom Wouters" <Tommaz@pandora.be> schreef in bericht
> news:7oDdb.45756$v93.1894515@phobos.telenet-ops.be...
>> hi everone,
>>
>> i am trying to write a function called shiftDown.
>> This function needs to move the contents of an array one place back .
>> ex. int[] intarray = new int[4]
>>
>> intarray[0] = 1;
>> intarray[1] = 2;
>> intarray[2] = 3;
>> intarray[3] = 4;
>>
>> then i want to use the function and i must have the following:
>> intarray[0] must then be 2
>> intarray[1] must be 3
>> intarray[2] must be 4
>> and intarray[3] must be 1
>>
>> i am working on this for days now and still can't figure it out this
>> is what i allready have but it doesn't work
>>
>> public void shiftDown() {
>> for (int i = 0; i < lengte2.length; i++) {
>> if ( lengte2[i] == lengte2.length) {
>> lengte2[i] = lengte2[0];
>> lengte2[i] = lengte2[i + 1];
>> }
>> }
>> }
>>
>> lengte2 is my array.
>>
>> TIA
>>
>> Tommaz
>>
>>
Tom,
I think we all like to help, but you will not be learning Java by letting
other people solve your homework for you....
Question : Can the shiftdown integer parameter be larger then the size of
the array?
Question : if it can be larger, should you do a full rotate ?
Brgds,
Herman
*********************************
--
Suse Linux Professional 8.1 on Athlon 1.1 Ghz 512 Mb
Anti Spam = remove the "dot" and the "at"
Registered Linux User #264690
|
|
0
|
|
|
|
Reply
|
timmermansdot.hermanat (6)
|
9/29/2003 7:21:14 PM
|
|
|
15 Replies
29 Views
(page loaded in 0.203 seconds)
Similiar Articles: how to identify which disks belong to which array? - comp.unix ...We have a E3000 machine with a A5100 array (7 slots - 14 disks). However, when I do a ... First of all, an A5100 is not a SSA, it is a SENA For your question: luxadm probe ... Volume not found - comp.unix.solarisOne lun is a raid 5 array of seven 17 GB disks, the other a raid 1 array of two 146 ... Why can I see these disks with the probe-scsi-all command but not see them with the ... hash table quadratic probing help please - comp.lang.java ...For example, if the array size is elevenand the first hashVal is zero, locations [2], [4], [7], and [9]are untouched in the first hundred probes (unless I botched myquick ... Extract Program change number formula - comp.music.midiDumb question prob. I am writing an app to send multiple program changes as well as ... too if necessary. > > Simplest way: remember the incoming dwValue in an array ... In an assignment A(I) = B, the number of elements in B and - comp ...Hello, well, let s say! i have simplified the prob I d like to solve an ODE where the input is not a constant but a sinusoidal excitation...U = ... DerInputStream.getLength(): lengthTag=127, too big ...I have found my prob : The Povider :) EjbCA use BouncyCastle Provider to encode ... Then I pass this byte array to X509Certificate getInstance method which throws the ... how do I find whether any slot is empty - comp.unix.solaris ...When I did: luxadm probe ARY001 Then I did: luxadm dispaly ARY001 I got the following o/p: SENA ... Chemometrics, PLS - comp.soft-sys.matlab... PctVar]=plsregress(X,y,ncomp) will give me my PLS model, and then to make a predection of the parameter for an unknown sample with measurement response in a 1xp array x ... variable capacitance and resistance with time - comp.soft-sys ...I use to create and xlswrite a cell array with variable names (sort of ... ... converter using simulink. Right now I'm working on the batteries model. My prob... Generating a `random' number between 0 and 1 with a higher ...>> [...] > > double prob_of_1 = 0.8; // or whatever > int rand = (Math.random() < prob_of_1 ... Generating an array with a series of start and end points - comp ... Generating a ... SCSI BUS Target Resets - comp.unix.solaris(e.g. hostA, array A, array B; then hostB, array A, array B in another). HTH Adrian ... SCSI errors on probe-scsi-all - comp.unix.solaris... the following: /pci@8,700000 ... Luxadm display - comp.unix.solarishow to identify which disks belong to which array? - comp.unix ... How do I find ... At first runa luxadm probe to see the HBAs. 2. Then try with /etc/powermt display dev ... No SCSI boot device found - comp.periphs.scsiHP Proliant ML350 G3 Server Windows 2003 HP 641 Array Controller 36 GB SCSI on slot 1 (system) 72 GB SCSI on slot 2 (data) I get those messages in that order whenever ... Could anyone give me the spice-mode.el - comp.emacsHi, All I am new to *NIX and I am thinking of writing spice code under Emacs. However, I have no idea of Emacs Lisp. Hence, I could not write a packa... Something bad happened to my gfortran installation - comp.lang ...Calling sub with N = 18 C:\gfortran\clf\probe_rsp>gfortran -v Built by Equation ... (For arrays one would call it automatic array): > 3) Something going wrong with ... IMASONIC Industry - TRL Phased array probesContact array probes. TRL / SE Arrays (Separate Transmit Receive) Typical Applications. Wrought / cast stainless steel components, austenitic ... DNA microarray - Wikipedia, the free encyclopediaSince an array can contain tens of thousands of probes, a microarray experiment can accomplish many genetic tests in parallel. Therefore arrays have dramatically ... 7/27/2012 6:32:59 PM
|