# Write a program that prompts the user to input a positive integer, it should then output a massage indicating whether the number is a prime number

0 votes
252 views
in Computer

## 1 Answer

0 votes
by (35 points)

Can help you with the logic (in JAVA)

1. Take input of any positive integer by the user
2. Use IF-Else statement with condition that input integer should be >0,else print Input is not positive integer (in the Else block)
3. In the IF block , now we have a positive integer. Use "for" loop from i= 1 to i= integer itself
• In the for block use IF-Else statement with condition that if integer % i==0(when integer is divided by i remainder=0) then counter++ or counter=counter+1 where counter is just a variable with initial value=0
• Else continue the loop with i++ or i=i+1

4. Outside the loop use IF-Else statement with condition that if counter==2 (that means divisible by 1 and number itself) then print that number is a prime number, else print it is a composite number

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer