Skip to content

Commit 9aa1488

Browse files
committed
Basic:- Solution to find if the number is Prime using For Loop
1 parent 4963d96 commit 9aa1488

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

‎src/Assignments/PrimeNumber.java‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,31 @@ public static void main(String[] args) {
88
Scanner input = new Scanner(System.in);
99
System.out.println("Enter the Number:");
1010
int n = input.nextInt();
11-
System.out.println(isPrime(n));
11+
System.out.println(isPrimeNumber(n));
12+
}
13+
14+
static boolean isPrimeNumber(int number) {
15+
int count = 0;
16+
17+
for(int i = 1; i <= number; i++){
18+
System.out.println("Count is " + count + " and i value is " + i);
19+
if (number % i == 0){
20+
System.out.println("i value is " + i);
21+
count ++;
22+
}
23+
24+
if (count >= 3){
25+
System.out.println("Exited the loop with count: " + count);
26+
break;
27+
}
28+
}
29+
if(count == 2){
30+
System.out.println("YES");
31+
return true;
32+
}else{
33+
System.out.println("NO");
34+
return false;
35+
}
1236
}
1337

1438
static boolean isPrime(int n){

0 commit comments

Comments
 (0)