Latest Diablo 3 News
Support the site! Become a Diablo: IncGamers PAL - Remove ads and more!

# Quick question for JAVA programmers/users.

Discussion in 'Off-Topic' started by Carnage-DVS, Jun 21, 2005.

1. ### Carnage-DVSIncGamers Member

Joined:
Jul 4, 2003
Messages:
3,169
0
Trophy Points:
346
Quick question for JAVA programmers/users.

I've got a couple of tough questions in a subject where the teacher, frankly, isn't teaching very well. Wondering if anyone could help (do =D) with the code on this. Questions are these.

1.Write a Boolean method that takes two loaded integer arrays of size s and returns true if they are identical.
2. Write a program that inverses an array object to it's reverse object.
3. Write a function/metho that takes a number and returns the number of non prime digits in the number.

Thanks for any help. Yeah i know, i should do it myself, but I can't even grasp the fundamentals of this class.

2. ### Bullet-Tooth TonyIncGamers Member

Joined:
Jul 2, 2003
Messages:
225
0
Trophy Points:
42
I don't know Java syntax very well, hope you'll be able to correct me if I have some syntax errors:
1) IdenticalTest = function (A1, A2, S) // A1, A2 - arrays, S - length
{
identical = true; //by default we think that arrays are equal
I=1; // It's the cycle counter - we'll begin with 1
while ((identical = true) and (I = S) // exit from cycle if we find an element that differs or reach the end
{
if (A1 <> A) // if an element of A1 differs from A2 ...
{identical = false;} // arays are no longer considered equal
I = I+1; // increase cycle counter
}
return identical; // return true or false from "identical" variable as a result
}
2) Didn't understand what does it mean to "inverse" an array.
3) Don't understand the task either. What is the "prime digit"?
I repeat, I don't remember Java syntax very well, so I'm not sure all symbols/keywords are what they should be, but pretty sure, that logic is correct.

3. ### HatsepsutBanned

Joined:
Jun 22, 2003
Messages:
985
0
Trophy Points:
0
Hmmm don't be too lazy. I haven't done java for quite some time but those are quite standard exercises so I bet you can google for them. That way you at least have to do some work.

4. ### Steel_AvatarIncGamers Member

Joined:
Jun 22, 2003
Messages:
3,087
0
Trophy Points:
255
1. Iterate through the first array, comparing each key's value to the corresponding value in the second array. If at any time they aren't equal, return false. Otherwise at the end, return true. No I won't give you the actual code.

2. If you mean reverse an array, initialise a second one, and then read the values from the first into the second, starting at the beginning of the first, and the end of the second.

3. Use the String class; convert your value to a string and then parse the string, incrementing a counter each time you encounter a non-prime digit.

5. ### EronakIncGamers Member

Joined:
Apr 28, 2005
Messages:
63
0
Trophy Points:
11
For the first one you needn't bother taking S, you can determine the size of the array from the Array.length value. This will also be subtly different on what your definition of identical is. Do the numbers have to be in the same order, how do you consider multiple array entries of the same number. If we are considering the easiest one, the numbers must be the same and in the same order then something like
Code:
```public boolean compare(int [] a, int [] b)
{
//not the same length, not the same array
if(a.length != b.length)
return false;

//just initialise this
boolean identical = true;

//loop through the array to the end
for(int i=0; identical && i < a.length; i++)
{
//set this to the boolean value of the expression
//comparing the two numbers we are at
identical = (a[i] == b[i]);
}

//return
return identical;

}
```
If this isn't what you mean by identical then you might need to modify it. If you mean it in the sense that two sets are identical (number of occurances of a number and order play no role) then you will need two nested loops, for a bag (order doesn't matter, number of occurances does) then thats a bit trickier.

The other two should be easy enough if you follow what everyone else said.

6. ### NwordBanned

Joined:
Jun 26, 2003
Messages:
711
0
Trophy Points:
0
If we gave them in C++ could you figure out the basic idea?

(My teacher always said C++ and Java are very similar...)

7. ### Carnage-DVSIncGamers Member

Joined:
Jul 4, 2003
Messages:
3,169
0
Trophy Points:
346
Yeah I did this already. Thanks for the help everyone.

As for the C++, I know they are very similar. I'm still knew to coding languages though, so it'll just confuse me.