[Java self-study] Double prime number, java Prime Number

Source: Internet
Author: User

[Java self-study] Double prime number, java Prime Number

1 package codeTask_FangFa; 2 // 5.30 double prime number is two prime numbers with a difference of 2. The program displays all the double prime numbers smaller than 1000. Display by format. 3 public class ShuangSuShu {4 public static void main (String [] args) {// the so-called main method; 5 int number = 3; 6 int first = 2; 7 System. out. println ("the double prime number less than 1000 is:"); 8 while (number <1000) {9 if (isSuShu (number) {10 int second = number; 11 if (second-first = 2) {12 System. out. println ("(" + first + "," + second + ")"); 13} 14 first = second; 15} 16 number ++; 17} 18} 19 20 public static boolean isSuShu (int number) {// determine whether the prime number is used; 21 for (int divisor = 2; divisor <= number/2; divisor ++) {22 if (number % divisor = 0) 23 return false; 24} 25 return true; 26} 27 28}

 

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.