Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Beginning Java
Arrays
Louis Hadjiandreou
Greenhorn
Posts: 1
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
If your array contains doubles, floats, ints or longs, you can use Math.abs() method.
Joanne
David Ulicny
Ranch Hand
Posts: 724
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
suppose that my_array is holding numbers
my_array[i] = my_array[i] * (-1);
SCJP<br />SCWCD <br />ICSD(286)<br />MCP 70-216
Megs Maquito
Ranch Hand
Posts: 84
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
i think Math.abs() as suggested is more OO and cleaner
I'm a Hood Ornament
Norm Radder
Rancher
Posts: 5008
38
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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.
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Naming Objects
about this array class
Question to authors: AJAX caching
Anonymous array
addAll
More...