LIVE Course for free

Rated by 1 million+ students
Get app now
0 votes
252 views
in Computer by (35 points)

Please log in or register to answer this question.

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

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...