-->

9/19/2019

prime number program

1import java.util.Scanner;
2 
3public class Prime {
4 
5    public static void main(String[] args) {
6        // TODO Auto-generated method stub
7        int temp, num;
8        boolean isPrime = true;
9        Scanner in = new Scanner(System.in);
10        num = in.nextInt();
11        in.close();
12        for (int i = 2; i<= num/2; i++) {
13            temp = num%i;
14            if (temp == 0) {
15                isPrime = false;
16                break;
17            }
18        }
19        if(isPrime)
20            System.out.println(num + "number is prime");
21            else
22                System.out.println(num + "number is not a prime");
23             
24         
25    }
26 
27}
Output:
445
445number is not a prime
NEXT ARTICLE Next Post
PREVIOUS ARTICLE Previous Post
NEXT ARTICLE Next Post
PREVIOUS ARTICLE Previous Post