EDIT by mw: Added Code Tags to restore original poster's formatting.
[ March 26, 2006: Message edited by: marc weber ] (Marilyn broke long line) [ March 26, 2006: Message edited by: Marilyn de Queiroz ]
I see two issues that are preventing this from compiling. The first is...
array calc = new array();
In Java, the syntax for creating arrays is a little different than for most other objects: You don't call a constructor called "Array." Instead, arrays are created as you already did 4 lines above this...
int array = new int;
So you've already got your array created, and you can remove the "new array()" line.
The next issue is when you try to call...
The method "display" is an instance method in a separate class called Two. So to use this method, you need to create an instance of Two and use that to call the method. For example...
Two myTwo = new Two(); myTwo.display(array);
These things will allow the code to compile. After that, see what the output tells you when you run.
PS: Note that I added Code Tags to your original post. This keeps your code formatting intact so it's easier for others to read. Please use these in future posts. [ March 26, 2006: Message edited by: marc weber ]
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
Joined: Mar 26, 2006
Joined: Mar 26, 2006
Is there anybody out there who can take this program and fix the entire thing? I've asked people for this already but nobody has helped me because there suggestions don't work. I've done everything I know... and I've even looked in my java book and I still can't get it. Can somebody please take the time and make it work? All it has to do is spit out the difference of the number and the last.
Can somebody please take the time and make it work?
No. That's not what we do here. We're trying to help people learn Java, and you won't learn anything by someone else fixing your code. Analyse what it does, and which part of what it's doing you don't understand, and we'll try to help you get going again. [ March 27, 2006: Message edited by: Ulf Dittmer ]
you're supposed to take 20 numbers at execution? AS in "java DifferenceMaker 1 2 3 4 5 6 ... 20" and spit out the differences between the last number and the one before it (not sure what that means, but I'll give it a shot) as in "output: 1 (20-19), 1 (19-18), 1 ... , 1"?
If that is the problem then here is a pseudo-code solution: 1. Take in the array (in the main method) 2. Print out some initial text like "the output is: " 2. run a backwards for loop over the length of the array (start at length-1, end at 1 (not 0 or you'll get an ArrayOutOfBoundsException), do index-- at each iteration) 3. For each member of the array (also each iteration of the loop) print out a line with something like: "the difference between input number "+index+" and input number "+index-1+" is "+array[index]-array[index-1]
Your output should be 19 lines beginning with: "the output is: " and each line looking like: "the difference between input number 20 and input number 19 is 1" "the difference between input number 19 and input number 18 is 1"
etc. till the end (of course the 1s will be replaced by the actual differences).
The main runtime problem is an ArrayOutOfBoundsException when you try to access array in the do-while loop.
Hint: Note that a do-while loop executes the "do" block first, and then checks the condition (Count < 20) before beginning another iteration. So by the time it recognizes that (Count < 20) is false, it's already tried to access array.