Results 1 to 3 of 3
  1. #1
    ajay.eeralla is offline Member
    Join Date
    Mar 2011
    Posts
    7
    Rep Power
    0

    Default does anyone know about the following error

    Java Code:
    package funfun;
    import java.math.BigInteger;
    /**
    *
    * @author ajay
    */
    public class Fun{
    private final static BigInteger ONE=new BigInteger("1");
    private final static BigInteger ZERO=new BigInteger("0");
    private final static BigInteger TWO=new BigInteger("2");
    public static BigInteger sqrt(BigInteger n) {
    BigInteger a = BigInteger.ONE;
    BigInteger b = new BigInteger(n.shiftRight(5).add(new BigInteger("8")).toString());
    while (b.compareTo(a) >= 0) {
    BigInteger mid = new BigInteger(a.add(b).shiftRight(1).toString());
    if (mid.multiply(mid).compareTo(n) > 0) {
    b = mid.subtract(ONE);
    } else {
    a = mid.add(ONE);
    }
    }
    return a.subtract(ONE);
    }//end of sqrt of n
    
    //legendre symbol
    public BigInteger legende(BigInteger n, int s) {
    
    BigInteger mone = new BigInteger("-1");
    BigInteger p = new BigInteger("" + s);
    BigInteger d = p.subtract(ONE).divide(TWO);
    BigInteger c = n.modPow(d, p);
    if (c.compareTo(ONE) == 0) {
    return ONE;
    } else {
    return ZERO;
    }
    }
    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
    
    int fcount=8;
    int [] factorbase={2,3,11,17,19,23,43,47};
    int k=0;
    BigInteger n= new BigInteger("1042387");
    BigInteger Sqrt=sqrt(n);
    BigInteger t=Sqrt.add(ONE);
    int sscount=0;
    BigInteger [] s=new BigInteger[500];
    BigInteger f;
    BigInteger m;
    while(t.compareTo(Sqrt.add(BigInteger.valueOf(41))!=0)
    {
    f=t.multiply(t).subtract(n).mod(n);
    for(int i=0;i<fcount;i++)
    {
    
    BigInteger z= BigInteger.valueOf(factorbase[i]);
    m=f.mod(z);
    if(m.compareTo(ZERO)==0)
    {
    s[k]=f;
    k++;
    sscount++;
    }
    }
    
    }
    for(int q=0;q<sscount;q++)
    
    {
    System.out.println(""+s[q]);
    }
    // if(jTextField2.getText().isEmpty())
    // jTextField2.setText(jTextField2.getText()+s[q]);
    // else
    // jTextField2.setText(jTextField2.getText()+","+s[q]);
    
    }
    
    
    }

    run:
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 500
    at funfun.Fun.main(Fun.java:6
    Java Result: 1
    BUILD SUCCESSFUL (total time: 0 seconds)
    Last edited by Eranga; 03-12-2011 at 12:41 AM. Reason: code tags added

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default

    Have you read the documentation?
    ArrayIndexOutOfBoundsException (Java Platform SE 6)

    db

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Yes, I'm sure hundreds of members in our forum comes with this error before. At least if you've search the forum you could find the solution yourself too. OR at least if you have a look at the documentation, as db mentioned above, you may solve the problem before posting here too.

Similar Threads

  1. java out of memory error-heap space error
    By elsanthosh in forum NetBeans
    Replies: 4
    Last Post: 06-15-2010, 09:31 AM
  2. Replies: 1
    Last Post: 03-10-2010, 01:53 PM
  3. Replies: 1
    Last Post: 12-05-2009, 07:28 AM
  4. Replies: 1
    Last Post: 10-26-2009, 04:38 PM
  5. Replies: 3
    Last Post: 01-23-2009, 08:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •