-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrimeOddSqrt.java
More file actions
41 lines (37 loc) · 1.09 KB
/
PrimeOddSqrt.java
File metadata and controls
41 lines (37 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.util.Scanner;
public class PrimeOddSqrt {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter first number");
int a = sc.nextInt();
System.out.println("Enter second number");
int b = sc.nextInt();
System.out.println("Enter third number");
int c = sc.nextInt();
checkPrime(a);
checkPrime(b);
checkPrime(c);
}
public static void checkPrime(int num){
boolean prime = true;
if(num <= 1){
prime = false;
}
for(int i = 2; i <= num/2; i++){
if(num % i == 0){
prime = false;
break;
}
}
if(prime){
double sqrt = Math.sqrt(num);
if(num % 2 == 0){
System.out.println(num + " Prime and Even , sqrt = " + sqrt);
}else{
System.out.println(num + " Prime and Odd , sqrt = " + sqrt);
}
}else{
System.out.println(num + " is not Prime");
}
}
}