Skip to content

Commit

Permalink
prime number
Browse files Browse the repository at this point in the history
  • Loading branch information
riteshgaigawali committed Jul 25, 2024
1 parent 457f04d commit bc0f7ef
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions problems/PrimeNumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,25 @@ public static void main(String[] args) {
int num = sc.nextInt();
sc.close();

boolean flag = false;
int flag = 0, medium;

for (int i = 2; i < num; i++) {
if (num == 0 || num == 1) {
System.out.print("This is not prime number.");
} else if (num % i == 0) {
flag = true;
if (num == 0 || num == 1) {
System.out.println("This is not a prime number.");
} else {
medium = num / 2;
for (int i = 2; i <= medium; i++) {
if (num % i == 0) {
flag = 1;
break;
}
}
if (flag == 1) {
System.out.println("This is not a prime number.");
} else {
flag = false;
System.out.println("This is a prime number.");
}
}

}

}

0 comments on commit bc0f7ef

Please sign in to comment.