0
Follow
0
View

How to solve the problem of #java#?

cyl821122 注册会员
2023-01-24 19:07

when number < 3 will not enter the for loop, flag will still be true.

dailiben 注册会员
2023-01-24 19:07

1. Problem: your i value is 2, but the for loop is i< =number-1, you can see that the value of 1 and 2 will not enter into the for loop, so the value of flag will remain the same.
2, Solution: you can add if to judge whether the input value is 1 and 2 or other cases, if it is 1 and 2 or other direct output results, otherwise enter the loop to judge whether it is prime.

About the Author

Question Info

Publish Time
2023-01-24 19:07
Update Time
2023-01-24 19:07

Related Question