Determine all prime numbers of 2~100, which are prime output and print

Source: Internet
Author: User

/*** Judging all primes of 2~100, is the prime number output and print * 10 a line break*/ Public classIsPrime { Public Static voidMain (string[] args) {intnum = 100;    Printprime (num); }     Public Static voidPrintprime (intnum) {        intCount = 0;//number of prime counts        /*Check all the numbers between the 2~num*/         for(inti = 2; I <= num; i++) {            /*This assumes that each number is prime*/            BooleanFlag =true; /*Check that each number is not a prime*/             for(intj = 2; J <= (int) math.sqrt (i); J + +) {                if(I%j = = 0){                        //entering the IF condition is not necessarily a prime number, so the switch changes.Flag =false;  Break; }            }            /*Print Prime number*/            if(flag) {System.out.print (i+ "\ T"); Count++; if(count%10 = = 0) {System.out.println (); }            }        }    }    /*Output Results: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 All in all*/}

Determine all prime numbers of 2~100, which are prime output and print

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.