Java rewrite "C Classic 100 Questions"--12

Source: Internet
Author: User

"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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.