JAVA basic programming exercises program [13 13] according to the conditions required numbers

 

13 [13 program requirements under the conditions of digital] Title: An integer plus 100 after it is a perfect square, plus 168 is a perfect square, what is the number is how much?

Program Analysis: Analyzing less than 100,000, the number 100 has been added after the first prescription, then the prescription and then 268 plus the number, if the result of the square root satisfies the following condition, i.e., is the result.

 

package cskaoyan;

public class cskaoyan13 {
	@org.junit.Test
	public void number() {
		int min = 1;
		int max = 100000;
		int m = 0;
		int n = 0;

		for (int i = min; i <= max; i++) {
			m = (int) Math.sqrt(i + 100);
			n = (int) Math.sqrt(i + 100 + 168);

			if (m * m == (i + 100) && n * n == (i + 100 + 168)) {
				System.out.println(i);
			}
		}
	}
}

 

Guess you like

Origin www.cnblogs.com/denggelin/p/11330320.html