Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   General Computer Support (http://www.velocityreviews.com/forums/f44-general-computer-support.html)
-   -   Please Help~ (http://www.velocityreviews.com/forums/t715927-please-help.html)

patrickAng 02-24-2010 09:07 AM

Please Help~java Collision Method~
 
import java.util.Scanner;

public class MDivisionQuadratic_TRY {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int[] index = new int[10];
int s;

do {
System.out.println("Please enter number to be store: (0 to stop)");
s = scan.nextInt();
int address = s%10;
boolean flag = true;
int address2=0;
int num=1;

int divi=0;

while (flag)
{

if (address >= index.length)
{
while (address-- > 0)
{
if (index[address] == 0)
{
index[address] = s;
System.out.println(s+" -- ("+address+")");
break;
}
else
if (address == 0 && s != 0)
System.out.println ("Array full, enter 0 to stop.");
flag = false;
}
}
else
if (index[address] == 0)
{
index[address] = s;
System.out.println(s+" -- ("+address+")");
flag = false;
}
else
{
/*
* collsion method( quadratic probe)
divi=s/10; // find the offset
address2=(address+divi)%307; // find the new address
//System.out.println("divi :"+divi);// get 918
System.out.println(s+" -- ("+address2+")");
address=address2;
*/

//-------------------------------
// PLEASE SOLVEE
//-----------------------------
address=(address+(num*num));
num++;


}
}// do wile loop collsion method
} while (s != 0);

System.out.println("\n\n-------------------------");
for (int i=0; i<index.length; i++)
System.out.println(i+"-----------"+index[i]);
System.out.println("-------------------------");
}
}

// if fell free, pls do contact me via my msn or hotmail address : patrick_18.5.90@hotmail.com[/email]

patrickAng 02-24-2010 09:17 AM

i'm new here...so hope u all who have programming back ground could give a hand...
 
i'm trying to store data into the array, when the current[index] is occupied, it will move to another location untill it found a empty [index]

the problem is : it went out of the array size...

secraser 03-03-2010 01:00 PM

I wish you good luck with this problem.


All times are GMT. The time now is 12:56 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.