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]);
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
posted
0
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
posted
0
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
posted
0
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).