Need help on creating a method.

I need help on creating a method that calculates the Greatest Common Divisor of two numbersx andy, then returns the greatest common divisord. So, I created this...

publicstatic _gcd (long x,long y){

int j = 1;

do{// loops to find the GCF

long[] mod_num_array;

mod_num_array[0] = y % x;

mod_num_array[j] = mod_num_array[j - 1] % x;

j++;

}while (mod_num_array[j] != 0);

return mod_num_array[j];// returns [b][i]d[/i][/b]

}

When I try to compile the method, i get an error saying thatreturn mod_num_array[j];// returns [b][i]d[/i][/b]

is missing the array start, when i put thelong[] mod_num_array;

outside the do-while, it says that mod_num_array[0] = y % x;

is missind the array start. So im lost, can someone please help. In advance, thanks for the effort.

[1468 byte] By [Yoan_Chiniquea] at [2007-10-1 19:19:43]
# 1

This linelong[] mod_num_array;

tells the compiler that the variable mod_num_array is a reference to an array of longs. It does not create an array. You need long[] mod_num_array = new long[some_int_length];

to create an array. You must specify the length of the array.

The second potential problem is variable scope. Any variable declared within a pair of braces { } exists only between those braces.

atmguya at 2007-7-11 15:24:09 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 2
Thanks for the help, I dint notice that.
Yoan_Chiniquea at 2007-7-11 15:24:09 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...