/*** 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