Skip to content

Commit

Permalink
Merge pull request tarunsinghofficial#430 from quytm/patch-1
Browse files Browse the repository at this point in the history
Prime check
  • Loading branch information
tarunsinghofficial committed Oct 20, 2020
2 parents 6f0383b + a61c93f commit d026f1f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Java_Programs_for_beginners/PrimeCheck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import java.util.Scanner;

class PrimeCheck {
public static void main(String args[]) {
int temp;
boolean isPrime = true;
Scanner scan = new Scanner(System.in);
System.out.println("Enter any number:");
int num = scan.nextInt();
scan.close();
for (int i = 2; i <= num / 2; i++) {
temp = num % i;
if (temp == 0) {
isPrime = false;
break;
}
}
if (isPrime)
System.out.println(num + " is a Prime Number");
else
System.out.println(num + " is not a Prime Number");
}
}

0 comments on commit d026f1f

Please sign in to comment.