"Program 36"
Title: Number of primes within 100
1. Program Analysis:
2. Program Source code:
1 /**2 * 3 * "program 36"4 * Title: Number of primes within 100. 5 * Program Analysis: The method of judging primes: to remove 2 to sqrt (this number) with a number, if divisible, indicates that the number is not a prime, and vice versa is a prime. 6 * 7 * @authorwww.cnblogs.com/java-1008 *9 */Ten One Public classJava36 { A - Public Static voidMain (string[] args) { - BooleanPrime; the intnum = 0; - for(inti = 2; I <= 100; i++) { -Prime =true; - for(intj = 2; J < Math.sqrt (i) + 1; J + +) { + if(i% j = 0 && i! = 2) { -Prime =false; + Break; A } at } - if(prime) { -System.out.print (i + "\ T")); - if(++num% 5 = = 0) { - System.out.println (); - } in } - } toSystem.out.println ("\ n Total" + num + "x")); + } - the}
Java rewrite "C Classic 100 Questions"--36