I'm trying to make an application to check if a specific number is a prime. Since the number is bigger than value of int or long, I had to use BigInteger, but I've slim knowledge about it so I'm hitting the wall. What I'm doing is checking if n is dividable by odd numbers(i) until i reaches root of the n. the value of n(10^24+7) is a prime number and I want to check bigger numbers such as 10^128+7. I'd appreciate any help.
import javax.swing.*;
import java.math.*;
public class prime {
public static void main(String[] args) {
BigInteger n = new BigInteger("1000000000000000000000007");
BigInteger h = new BigInteger("2");
int r;
for(BigInteger i = new BigInteger("3");n.compareTo(i.multiply(BigInteger.valueOf(i)))>=0;i.add(BigInteger.valueOf(h))) {
if(n.divideAndRemainder(i)==0){
r=0;
}else{
r=1;}
}
if(r=0){
System.out.println("not prime");}else{
System.out.println("prime");}
}
}