Use a for loop to find the smallest integer n such that n^3 is greater than 1000
So I came out with below code
public class Chapter4 {
static int n = 0;
public static void main(String[] args) {
for (int i = 1; Math.pow(i, 3) <= 1000; i++) {
n = i;
}
System.out.println("Smallest i is " + n);
}
}
I get value answer 21 which looked like not the smallest integer. What is wrong with my logic ? I thought the value n should be 10 ?