aspose file tools*
The moose likes Java in General and the fly likes Array problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Array problem" Watch "Array problem" New topic
Author

Array problem

peterx peter
Greenhorn

Joined: Nov 02, 2004
Posts: 19
Hi!
This is an insertion sort program, the program is OK
But my question is about out put of (j):
--------------------------------------------------
A[j + 1] = a;
System.out.print(j+" ");
--------------------------------------------------
The out put is -1,0,0,-1,1,-1,1)
Which (j) dose take these values and how dose it work???

Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

The best way to understand would be to run the program in a debugger and step through it one statement at a time, paying attention to the values of all the relevant variables. Of course, first you'd have to be sure to understand the algorithm being used.


[Jess in Action][AskingGoodQuestions]
Ramesh Shanmugam
Ranch Hand

Joined: Sep 13, 2004
Posts: 132
it is values of J that you decrease using J-- in the forloop..

each time it decreases J's value and that leads to 1, 0, -1 etc....


Ramesh Shanmugam - SCJP 1.5
 
Consider Paul's rocket mass heater.
 
subject: Array problem