|
It is currently Thu May 02, 2024 4:29 pm
|
Author |
Message |
ElevenBravo
King
Joined: Wed Apr 16, 2003 2:18 pm Posts: 1976 Location: Sexy Town
|
mmm irish cream mocha....
_________________ Contrary to popular belief, America is not a democracy, it is a Chucktatorship.
|
Thu Mar 24, 2005 3:14 pm |
|
|
derf
Minor Diety
Joined: Fri Apr 11, 2003 2:17 pm Posts: 7721 Location: Centre of the sun
|
I remember when i used to post stuff like that on a highly technical thread that i didnt understand.
Satis ended up knocking off something like 500 post count.
Ah the old days.
_________________ "Well a very, very hevate, ah, heavy duh burtation tonight. We had a very derrist derrison, bite, let's go ahead and terrist teysond those fullabit who have the pit." - Serene Branson
|
Fri Mar 25, 2005 12:14 pm |
|
|
ElevenBravo
King
Joined: Wed Apr 16, 2003 2:18 pm Posts: 1976 Location: Sexy Town
|
Man, thats tough, I guess its a good thing I dont give a poop about my post count.
<-- Drinking some java right now.
_________________ Contrary to popular belief, America is not a democracy, it is a Chucktatorship.
|
Sun Mar 27, 2005 8:00 am |
|
|
derf
Minor Diety
Joined: Fri Apr 11, 2003 2:17 pm Posts: 7721 Location: Centre of the sun
|
New Problem!!!
Maybe this is something more for GFree...
I have a 5*5 2D array of integers, and i need to write some code that prints the column with the most odd integers.
I am totally stuck. Im using the code below and i get the following compile-time error: (sorry about indentation, the [code ][/ code] tags dont use spaces)
Here is the code im using: (Notice i have not yet written a System.out.println line yet because i first want it atleast to compile! | | | | Code: public class Ws2Ex2 { public static void main (String args []) { int[][] ex2Arr = {{2,1,4,6,8},{2,1,4,6,8},{2,1,4,6,8},{2,1,4,6,8},{2,1,4,6,8}}; int colPoint; int prevTally = 0; int tally; for (int row = 0; row < ex2Arr.length; row++) { tally = 0; for (int col = 0; col < ex2Arr[row].length; col++) if (ex2Arr[row][col] % 2 == 0) tally++; if (tally > prevTally) { prevTally = tally; colPoint = col; } } } } | | | | |
|
Wed Mar 22, 2006 6:53 pm |
|
|
RB
Emperor
Joined: Wed Apr 16, 2003 1:25 am Posts: 2560
|
The variable col does not exist on the place you use it. (I think Pig mentioned the rule)
So, now it compiles. But I'm not sure what is an *odd* nr.
You do not have the required permissions to view the files attached to this post.
|
Thu Mar 23, 2006 10:11 am |
|
|
Satis
Felix Rex
Joined: Fri Mar 28, 2003 6:01 pm Posts: 16650 Location: On a slope
|
'odd' numbers are 1, 3, 5, 7, 9, 11, 13, 15, etc. Ie, divide by 2 and see if there's a remainder. If there is, it's an odd number.
I could probably do this in php in 20 minutes, but since it's Java I can't be of much help.
_________________ They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.
|
Thu Mar 23, 2006 10:35 am |
|
|
derf
Minor Diety
Joined: Fri Apr 11, 2003 2:17 pm Posts: 7721 Location: Centre of the sun
|
Cheers, ill give it a look later tonight.
_________________ "Well a very, very hevate, ah, heavy duh burtation tonight. We had a very derrist derrison, bite, let's go ahead and terrist teysond those fullabit who have the pit." - Serene Branson
|
Thu Mar 23, 2006 10:45 am |
|
|
RB
Emperor
Joined: Wed Apr 16, 2003 1:25 am Posts: 2560
|
Ok. But let me do some additional notices here: First you are searching through the columns of one matrix, which would mean that you have to fix the second index and look up by first for the count of odd numbers. So the loop would look like:
Second: what happens when there are no colmuns with odd numbers or when there are two colmuns with the came count of odd numbers? Third: This one
will return you true if the number is even.
See attachment if you'd like.
You do not have the required permissions to view the files attached to this post.
|
Thu Mar 23, 2006 12:04 pm |
|
|
derf
Minor Diety
Joined: Fri Apr 11, 2003 2:17 pm Posts: 7721 Location: Centre of the sun
|
Im too dumb to work out what that does in my mind. I havent got that far yet. I did identify this problem, but i will solve it when i actually get there. Yeh, i know. I changed that yesderday with:
Still havent looked at the files yet. Ive had no free time today.
|
Thu Mar 23, 2006 12:28 pm |
|
|
derf
Minor Diety
Joined: Fri Apr 11, 2003 2:17 pm Posts: 7721 Location: Centre of the sun
|
Elementary question:
What is x?
int[][] ex2Arr = {{2,1,4,6,8},{2,1,4,6,8}}
int i = 0;
x = ex2Arr[i].length;
_________________ "Well a very, very hevate, ah, heavy duh burtation tonight. We had a very derrist derrison, bite, let's go ahead and terrist teysond those fullabit who have the pit." - Serene Branson
|
Thu Mar 23, 2006 4:05 pm |
|
|
Satis
Felix Rex
Joined: Fri Mar 28, 2003 6:01 pm Posts: 16650 Location: On a slope
|
x=5.
doesn't the .length method give you the number of elements in the array? And since i is defined as being 0, it references the first array of the array, which is 5 elements big.
right? I don't know java, but this looks an awful lot like other programming languages I've used (kinda a fusion of javascript and visual basic .net and shit)
_________________ They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.
|
Thu Mar 23, 2006 4:35 pm |
|
|
derf
Minor Diety
Joined: Fri Apr 11, 2003 2:17 pm Posts: 7721 Location: Centre of the sun
|
Nah, its mainly just "shit".
You'd probably find Java a piece of piss Sat. I used to like it, now i fucking hate it with a vengeance. Its too low-level for me. I like to be on top!
You do not have the required permissions to view the files attached to this post.
|
Thu Mar 23, 2006 4:39 pm |
|
|
RB
Emperor
Joined: Wed Apr 16, 2003 1:25 am Posts: 2560
|
1. Yes. But function do not get actually the whole array but the pointer to it.
2. Not beyound loops exactly. You can use them at any place in the function after the place where they are declared.
3. The value -1 is just an value which is not correct value of an index. In principle you could use -2, -3 etc. If function does not find any passing column, this parameter (it is return parameter as well) will stay set on -1 and the function will return it, so you can know that matrix consist of even numbers only. You can use one new boolean variable, which would be initialized to false on the start of the function, and assigned to true, when the first colmun with odd numbers is found.
4. Yes
5. Yes
6. If you mean, would (mat[0].length = 5) be correct, the answer is no. The variable length is declared as *final* which means that it cannot be changed after it is once assigned.
7. Nope... i is still just an counter.
8. The code int n = mostOddCol(ex2Arr); does the same as
int n;
n = mostOddCol(ex2Arr);
- So, the variable n will be declared.
- After that it will be assigned to a returned value from mostOddCol(ex2Arr).
- mostOddCol(ex2Arr) is the call of method mostOddCol with one argument - 2D array ex2Arr.
Fine manual: http://java.sun.com/docs/books/tutorial/java/TOC.html
_________________ ++
|
Thu Mar 23, 2006 6:22 pm |
|
|
derf
Minor Diety
Joined: Fri Apr 11, 2003 2:17 pm Posts: 7721 Location: Centre of the sun
|
Now im screwing around with inheritance. Im getting my head around it, slowly, but (hopefully) surely.
Any tips you got to offer GFree?
_________________ "Well a very, very hevate, ah, heavy duh burtation tonight. We had a very derrist derrison, bite, let's go ahead and terrist teysond those fullabit who have the pit." - Serene Branson
|
Thu Apr 20, 2006 2:25 pm |
|
|
Satis
Felix Rex
Joined: Fri Mar 28, 2003 6:01 pm Posts: 16650 Location: On a slope
|
children inherit from parents
parents don't inherit from children
_________________ They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.
|
Thu Apr 20, 2006 2:36 pm |
|
|
Who is online |
Users browsing this forum: No registered users and 2 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|