File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Arrays" Watch "Arrays" New topic


Louis Hadjiandreou

Joined: Aug 24, 2005
Posts: 1
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

Joined: Aug 05, 2005
Posts: 3742
If your array contains doubles, floats, ints or longs, you can use Math.abs() method.

David Ulicny
Ranch Hand

Joined: Aug 04, 2004
Posts: 724
suppose that my_array is holding numbers

SCJP<br />SCWCD <br />ICSD(286)<br />MCP 70-216
Megs Maquito
Ranch Hand

Joined: May 18, 2005
Posts: 84
i think Math.abs() as suggested is more OO and cleaner

I'm a Hood Ornament
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 696
A value being in an array doesn't really have anything to do with the problem other than the syntax of the reference.
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.
I agree. Here's the link:
subject: Arrays
It's not a secret anymore!