File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Arrays - How do I show the array index postion? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Arrays - How do I show the array index postion?" Watch "Arrays - How do I show the array index postion?" New topic
Author

Arrays - How do I show the array index postion?

Heather Carey
Greenhorn

Joined: Nov 26, 2011
Posts: 15
In the program below, the output only displays the Transaction amount, but not the index position in my array. In this section immediately below, what can I do to not only show the amount of the transaction, but where it is in the index of the array.

i.e Transaction 5: 100.00.

Right now it just prints...

Transaction 100.0

//Present each transaction
for (int i=0; i<transactions.length; i++) {
System.out.println ("Transaction " + transactions[i]);


--------------------------------------…
James Boswell
Ranch Hand

Joined: Nov 09, 2011
Posts: 657
    
    2



Remember i will start at 0.
Heather Carey
Greenhorn

Joined: Nov 26, 2011
Posts: 15
EDITED: Never mind. My post below doesn't work.

--------------------------------------------------
Could I change it to:

System.out.println ("Transaction " + i + transactions[i]);

Thanks,

Heather
James Boswell
Ranch Hand

Joined: Nov 09, 2011
Posts: 657
    
    2

Heather

Why doesn't it work?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32830
    
    4
Have you tried + i + 1, even though I know that won’t work? You do need to explain the problem, otherwise we can’t halp.

And welcome to the Ranch
Heather Carey
Greenhorn

Joined: Nov 26, 2011
Posts: 15
I'm not sure why my last suggestion wouldn't work. When I entered the code and ran it, it gave me numbers that didn't seem to be double. More like Hex numbers instead.

Next I have to figure out how to make an array sort numbers, but I wanted to try and invoke the sort method (away from the main), but I'll look through the forums to see if anyone had a similar problem.

Thanks,
Heather
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32830
    
    4
So what did your hex numbers look like? Please show us the code which gave hex numbers? Are you trying to print the whole array? You get hex numbers if you do that, for reasons you will find out if you read about the toString() method.
Heather Carey
Greenhorn

Joined: Nov 26, 2011
Posts: 15
When I ran it the way I wrote it, the numbers became four wide and had a letter and - in the set.

i.e. 24-23 or 1F45

I could try to reproduce what i did, but I already fixed it with the other response. I most likely typed it in wrong from what I thought I put.

Someone told me that I could have used () around my +i and increased it by 1 so that the transaction count started at 1 instead of 0 (1 +1).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Arrays - How do I show the array index postion?
 
Similar Threads
Help on testprogram and subclass please
Very Confused!!
Null or Empty object (Return Type)
Confused with Synchronization
Hi check this code.It is not going in if condition