Judge how many primes are there between 101~200?
1 PackageHimi.hebao;2 3 /**4 * (1). Write the function IsPrime () to determine whether the input data is a prime number (2). Traverse to determine whether the data between 101~200 is a prime number and count5 * 6 * @authorAdministrator7 * 8 */9 Ten Public classTestDemo05 { One A Public Static voidMain (string[] args) { - intCount = 0; - the for(intA = 101; A <= 200; a++) { - if(IsPrime (a)) {//Call the IsPrime () method - System.out.println (a); -count++; + } - + } ASystem.out.println ("The prime number of the 101~200 of the output is altogether:"); at System.out.println (count); - - } - /** - * <pre> - * Used to determine if a number is a prime, if it is prime, returns True, otherwise false in * </pre> - * to * @parama + * The value entered - * @returntrue, False the */ * $ Private Static BooleanIsPrime (intN) {Panax Notoginseng BooleanFlag =true; - if(n = = 1) { theFlag =false; +}Else { A for(inti = 2; I <= math.sqrt (n); i++) { the if((n% i) = = 0 | | n = = 1) {//if it can be divisible, it is not a prime number, return False +Flag =false; - Break;//jumping out of the loop, that's the key $}Else { $Flag =true; - } - } the } - returnFlag;Wuyi the } - Wu}
Java Fundamentals Hardening 04: Judging How many primes are between 101~200