【Program2] Question: determine the number of prime numbers between-and output all prime numbers.
Program Analysis 2: Shenma is a prime number. I don't know the prime number, I know it. That's all !! Prime number. In a natural number greater than 1, except for 1 and the integer itself, it cannot be divisible by other natural numbers. In other words, only the natural numbers of two positive factors (1 and itself) are prime numbers. When I think about this question, I first think about the profiteering solution. It is only between 101--200 and there are not many prime numbers returned by public int Sushu (int I, then the for loop 101--200 will be ready.
Package endual; public class qanswer {public int Sushu (int n) {Boolean issushu = false; For (INT I = 2; I <n-1; I ++) {// This number is enough to get the remainder by Division of 2. // if the remainder is 0, it indicates that int res = n % I can be divisible; If (RES = 0) {return 0; // return 0} return N;} if it is not a prime number ;}}
Main class call
Package endual; public class main ,.... How many public static void main (string [] ARGs) {// todo auto-generated method stub // int n = 8; qanswer Qu = new qanswer (); For (INT n = 101; n <= 200; n ++) {// obviously the time complexity is very huge, int res = Qu. sushu (n); If (0! = Res) {system. Out. println (RES );}}}}
In this way, you can