5.13 (Find the largest n such that n3<12,000) Use a while loop to find the largest
integer n such that n3 is less than 12,000.
public class ProgrammingEx5_13 { public static void main(String[] args) { int n = 1; while (Math.pow(n, 3) <= 12000) { n++; } n--; System.out.println("The n is " + n); System.out.println("The n^3 is " + Math.pow(n, 3)); } }
No comments :
Post a Comment