Please Help~

Discussion in 'General Computer Support' started by patrickAng, Feb 24, 2010.

  1. patrickAng

    patrickAng

    Joined:
    Feb 16, 2010
    Messages:
    2
    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);
    System.out.println("-------------------------");
    }
    }

    // if fell free, pls do contact me via my msn or hotmail address : patrick_18.5.90@hotmail.com[/email]
     
    Last edited: Feb 24, 2010
    patrickAng, Feb 24, 2010
    #1
    1. Advertising

  2. patrickAng

    patrickAng

    Joined:
    Feb 16, 2010
    Messages:
    2
    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...
     
    patrickAng, Feb 24, 2010
    #2
    1. Advertising

  3. patrickAng

    secraser

    Joined:
    Mar 1, 2010
    Messages:
    1
    I wish you good luck with this problem.
     
    secraser, Mar 3, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tpg comcntr

    HELP! HELP! PLEASE, PLEASE, PLEASE

    tpg comcntr, Feb 14, 2004, in forum: Computer Support
    Replies:
    11
    Views:
    893
    michael turner
    Feb 15, 2004
  2. Nick

    Computer problems please please please help

    Nick, Jun 4, 2004, in forum: Computer Support
    Replies:
    0
    Views:
    470
  3. smokin@aol.com

    Please need help with cisco router, please can anyone help

    smokin@aol.com, Oct 30, 2004, in forum: Computer Support
    Replies:
    2
    Views:
    552
    David Hemingsley
    Oct 31, 2004
  4. The Martian

    Help Help Help Please Pentax S5i info needed

    The Martian, May 19, 2008, in forum: Digital Photography
    Replies:
    2
    Views:
    497
    The Martian
    May 20, 2008
  5. The Martian

    Help Help Help Pentax S5i Help needed (Please)

    The Martian, Jun 4, 2008, in forum: Digital Photography
    Replies:
    14
    Views:
    1,570
    ASAAR
    Jun 20, 2008
Loading...

Share This Page