Home > Back-end >  This is a program to determine whether primes, want to know what is the role of p?
This is a program to determine whether primes, want to know what is the role of p?

Time:09-27

Public class wanshu {
Public static void main (String [] args) {
Scanner sc=new Scanner (System. In);
System. The out. Println (" please enter a positive integer ");
Int x=sc. NextInt ();
Int p=0;
for(int i=2; iIf I==0) (x % {
System. The out. Println (" you entered is not a prime number ");
P=1;
break;
}
}
If (p==0) {
System. The out. Println (" you input is a prime number ");

}

Sc. The close ();

}
}

CodePudding user response:

A tag, the default markup is 0 is a prime number, if the number of cycle can be divided exactly by the tag to change to 1, jumped out, 1 is not a prime number

CodePudding user response:

Find a prime number p's role is to record your, because the program must increase from 2 to start looking for the number of factors, and know that found the factor can think that is not a prime number, can't find the words you need to record is a prime number, can't find any record is need to loop, so you need to have a p to identify whether found,
  • Related