Pages

Friday, 19 August 2016

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

5.12 (Find the smallest n such that n2>12,000n2>12,000) Use a while loop to find the smallest integer n such that n2n2 is greater than 12,000.

public class ProgrammingEx5_12 {
 
 public static void main(String[] args) {
 
  int n = 1;
  while (Math.pow(n, 2) <= 12000) {
   n++;
  }
 
  System.out.println("The n is " + n);
  System.out.println("The n^2 is " + Math.pow(n, 2));
 
 }
}

No comments :

Post a Comment