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