In my code i am just trying to make a simple program that tells you if one number can divide into another number evenly (in this case that number is 3). right now I am saying that if x (the number doesnt divide evenly add 0.01 to it, that gives me the stack overflow error. If I make the value 0.2 it says that 9 is a divisible of three when really the next thing number that divides into three after three is 6
public class divisible {
public static void divide(double x) {
double three = 3;
double value = x%three;
if (value==0) {
System.out.println(x + " is a divisible of 3 ");
return;
}else{
//System.out.println("x does not divide evenly into 3");
divide(x+(.01));
}
}
public static void main(String args[]) {
divide(4);
}
}
threeand to assign3to it. You should have a meaningful name, and make it a class variable.