Ask for all primes between 1-100

Source: Internet
Author: User

All primes between the console output 1-100. A prime number is a positive integer divisible only by 1 and by itself.

1  Public classPrimenumber {2      Public Static voidMain (String args[]) {3         intCount = 0;4         BooleanIsPrime;//defines whether a Boolean variable is a prime number. Yes: true; No: false5          for(inti = 2; I <= 100; i++) {6IsPrime =true;7             intK = (int) math.sqrt (i);8              for(intj = 2; J <= K; J + +) {9                 if(i% j = 0) {TenIsPrime =false;//If I can be divisible, then it is not a prime number. One                      Break; A                 } -             } -             if(isprime) { theSystem.out.print (i + "\ T")); -count++; -                 if(count% 5 = = 0) - System.out.println (); +             } -         } +     } A}

Ask for all primes between 1-100

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.