Friday 19 August 2016

Chapter 5 Exercise 13, Introduction to Java Programming, Tenth Edition Y. Daniel LiangY.

5.13 (Find the largest n such that n3<12,000n3<12,000) Use a while loop to find the largest integer n such that n3n3 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