Evaluate the prime number of three digits

Source: Internet
Author: User

I haven't done it yet. There were so many methods.

First, I don't know what a prime number is!

Prime Number: only the number divided by itself and 1


The post replies with many methods:

class Zhishu {        public static void main(String[] args)         {                int count=0;                for(int i=1;i<=100;i++)                {                        count=0;                        for(int j=1;j<=i;j++)                        {                                if(i%j==0)                                {                                        count++;                                }                        }                        if(count==2||count==1)                        {                                System.out.print(i+" ");                        }                }        }}
package com.ms.test;public class GetSushu {        /**         * @param args         */        public static void main(String[] args) {                // TODO Auto-generated method stub                for(int x=100;x<=999;x++){                        boolean flag=true;                        for(int y=2;y<x;y++){                                if(x%y==0){                                        flag=false;                                        break;                                }                        }                        if(flag){                                System.out.println(x);                        }                                        }        }}



Determines whether a three-digit number is a prime number.

Import Java. util. extends; public class primenum {public static void main (string [] ARGs) {Using SC = new using (system. in); system. out. println ("enter a three-digit number"); int num = SC. nextint (); If (Num <100 | num> 999) throw new runtimeexception ("input data is not required"); getprime (Num );} public static void getprime (INT num) {for (INT x = 2; x <num; X ++) {If (Num % x! = 0) {If (x = num-1) {system. out. println (Num + "");} continue;} else {system. out. println (Num + "Not Prime"); break ;}}}}


List all the prime numbers between 100 and the three numbers you entered (excluding 100)

Import Java. util. extends; public class totalprimenum {public static void main (string [] ARGs) {extends SC = new evaluate (system. in); system. out. println ("enter a three-digit number"); int num = SC. nextint (); If (Num <100 | num> 999) throw new runtimeexception ("input data is not required"); getprime (Num );} public static void getprime (INT num) {int COUNT = 0; // number of counter records W: For (INT x = 101; x <= num; X ++) {q: For (INT y = 2; y <X; y ++ ){ If (X % Y! = 0) {If (y = x-1) {system. out. print (x + "\ t"); count ++; Continue W;} continue Q;} else {continue W ;}} system. out. println (); system. out. println ("101 to" + num + "Total prime number:" + count );}}


Evaluate the prime number of three digits

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.