Why is my code producing an out of range error? It produces an error if I try int, long, float, or double when I initate the variable n in the 3rd line. This is happening for all my programs in Eclipse, although 600851475143 is clearly within the range of long or float.
public class LargestPrimeFactor {
public static void main(String arg[]){
long n = 600851475143;
for(float i=2; i<= n; i++){
if((n%i==0)&&(n!=i)){
n/=i;
while((n%i==0)&&(n!=i)){
n/=i;
}
}
}
System.out.println("The greatest prime divisor is "+n+".");
}
}