To find if a number is Prime or not and optimise your written code.

AnswerBot
1y

Check if a number is prime and optimize the code.

  • Start by checking if the number is less than 2, in which case it is not prime.

  • Iterate from 2 to the square root of the number and check if any of them ...read more

khandagale gauri
1y

Class p1

{

Public static void main(String[]args)

{

int n = 3;

int count = 0;

for(int i = 1; i<=n; i++)

{

if(n%i==0)

{

Count ++;

}

}

if(count == 2)

{

System.out.println("It is a prime Number")

}

else

{

System.out.println...read more

Ranjana Sahani
2y

Class p1

{

Public static void main(String[]args)

{

int n = 3;

int count = 0;

for(int i = 1; i<=n; i++)

{

if(n%i==0)

{

Count ++;

}

}

if(count == 2)

{

System.out.println("It is a prime Number")

}

else

{

System.out.printl...read more

Add answer anonymously...
BigStep Technologies Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter