1. Member
Join Date
Mar 2011
Posts
7
Rep Power
0

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) {
if (mid.multiply(mid).compareTo(n) > 0) {
b = mid.subtract(ONE);
} else {
}
}
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);
int sscount=0;
BigInteger [] s=new BigInteger[500];
BigInteger f;
BigInteger m;
{
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 01:41 AM. Reason: code tags added

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

db

3. 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.

Posting Permissions

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