Java algorithm question 2. Determine how many primes are in between 101-200, and output all primes.

Source: Internet
Author: User

[Original reprint annotated Source]

Title 2: Determine how many primes are in between 101-200, and output all primes.

Ideas:

Prime (prime number) is the addition of 1 and itself, no other numbers can be divisible by it

Java Code Implementation:

1  PackageJichu;2 3  Public classJICHU24 {5      Public Static voidMain (string[] args)6     {7         //For Loop traversal 101-2008          for(inti = 101; I < 200; i++)9         {Ten             Booleanb =false; One              A             //Inner Loop to determine if I is a prime number -              for(intj = 2; J <= I-1; J + +) -             { the                  -                 //except for 1 and itself, if I can divide the other numbers by B = False -                 if(i% j = 0 ) -                 { +b =false; -                      Break; +                 } A                  at                 //B = True if not divisible -                 Else -                 {    -b =true; -                 } -             } in              -             //if B = true, print out to             if(b = =true) +             { - System.out.println (i); the             } *         } $     }Panax Notoginseng}

[Original reprint annotated Source]

Java algorithm question 2. Determine how many primes are in between 101-200, and output all primes.

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.