Michael Pickens wrote:I am working on yet another homework assignment. This assignment is asking me to write a program which creates an array with its size determined by users and filled with random numbers between 1 and 100.
I must obtain the number of random numbers from the user through a GUI dialog box.
The 2 guidelines that my professor is requiring are:
1) My program should have at least two methods, "displayArray" and "reverse"
2) I am not allowed to create a new array within the method "reverse" to perform the task.
I have this code completely written, and I am having trouble reversing ALL the digits.
Output of my program: 7 random digits
myArray[0] = 5
myArray[1] = 14
myArray[2] = 88
myArray[3] = 18
myArray[4] = 20
myArray[5] = 8
myArray[6] = 46
myArray[7] = 100
After reversing the array
myArray[0] = 100
myArray[1] = 46
myArray[2] = 8
myArray[3] = 20
myArray[4] = 20
myArray[5] = 8
myArray[6] = 46
myArray[7] = 46
And since I am not allowed to simply make a new array, the code posted below is how I am handling the reverse.
Thanks again for the help.
Michael Pickens wrote:What started out for me as a logical process has now turned into a big guessing game . when i added the /2 to the length, it only prints out like this:
thus you can see I am missing 4 out of 7 indexes.. i suppose that is because arrayOne.length/2 = 3 (7/2=3).
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
fred rosenberger wrote:
The idea is to write small, simple methods that can be tested into oblivion so that you are SURE they work...then you use them whenever you need to, however you need to.
Michael Pickens wrote:I dont know what to do. Pen and paper "playing computer" doesn't make sense to me. When I do it, i pretend that my array size is 5 and trace it through. I see that when I swap, that I end up swapping back with the third swap... I do not understand how to fix the problem.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Michael Pickens wrote:WOO again as I was typing the last reply, I found my answer!!
Thanks again for all your help, sorry I am so frustrating to help!
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Out on HF and heard nobody, but didn't call CQ? Nobody heard you either. 73 de N7GH
Les Morgan wrote:Ever since CompSci-101 I liked using recursion for this type of problem.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
We should call you "Mr. Recursion".
Out on HF and heard nobody, but didn't call CQ? Nobody heard you either. 73 de N7GH
Les Morgan wrote:I have not said that my way of doing things is better than yours, but it is my preference, as I stated...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Campbell Ritchie wrote:I would also suggest you do it the object-oriented way...
Winston Gutkowski wrote:
... - but I'd still say it's not a "natural" way of programming unless you're a mathematician or used to functional languages.
Out on HF and heard nobody, but didn't call CQ? Nobody heard you either. 73 de N7GH
Hai Thompson wrote:What do you think about it? Please correct me if I have any wrongs in my code.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Les Morgan wrote:BTW: I am also one that finds great delight in seeing small bits of code do a lot.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Nothing wrong, AFAICS; but a few minor points:
...
Winston Gutkowski wrote:
6. I really like all your throws clauses - very nice. I wish more people did it (including me ).
Hai Thompson wrote:Thanks Winston, I got all things you mentioned
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Les Morgan wrote:BTW: I am also one that finds great delight in seeing small bits of code do a lot...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
get schwifty. tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|