Nagendra Reddy
Jan 10, 2022

Number is prime or not?

public class Main {

public static void main(String[] args) {
int num = 33, i = 2;
boolean flag = false;
while (i <= num / 2) {
// condition for nonprime number
if (num % i == 0) {
flag = true;
break;
}

++i;
}

if (!flag)
System.out.println(num + " is a prime number.");
else
System.out.println(num + " is not a prime number.");
}
}

33 is not a prime number.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response