"Program 12"
Title: Determine the number of primes between 101-200 and the output of all primes.
1. Program Analysis: The method of judging the prime number: The number is removed from 2 to sqrt (this number), if it can be divisible, it is not prime, the inverse is prime.
2. Program Source code:
1 /*this article transferred from blog: www.cnblogs.com/java-1002 "program 12"3 title: Determine the number of primes between 101-200 and the output of all primes. 4 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. 5 */6 7 Public classJava12 {8 9 Public Static voidMain (string[] args) {Ten BooleanPrime; One intnum = 0; A for(inti = 101; I <= 200; i++) { -Prime =true; - for(intj = 2; J < Math.sqrt (i) + 1; J + +) { the if(i% j = 0) { -Prime =false; - Break; - } + } - if(prime) { +System.out.print (i + "")); A if(++num% 5 = = 0) { at System.out.println (); - } - } - } -System.out.println ("\ n Total" + num + "x")); - } in}
Java rewrite "C Classic 100 Questions"--12