• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Arrays

 
Louis Hadjiandreou
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I turn a negative array element value into a positive?
I am to use a void changeSize method to do this so what code could I use?

the array is called, my_array[i];
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your array contains doubles, floats, ints or longs, you can use Math.abs() method.
 
David Ulicny
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
suppose that my_array is holding numbers
 
Megs Maquito
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think Math.abs() as suggested is more OO and cleaner
 
Norm Radder
Bartender
Posts: 1363
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A value being in an array doesn't really have anything to do with the problem other than the syntax of the reference.
Given:
int x
int[] ax

anywhere you can use x you can use ax[j]. they both refer to an int.
Same is true for any primitive and Object.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic