Advertisement
Waliullah8328

Input N number and get prime or not

Feb 2nd, 2021
599
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Question3 {
  6.     public static void main(String[] args) {
  7.         Scanner input = new Scanner(System.in);
  8.         int n ,i,j;
  9.         int count = 0;
  10.         System.out.print("Test Case = ");
  11.         n = input.nextInt();
  12.         for (i=0;i<n;i++)
  13.         {
  14.             int arr[] = new int[n];
  15.             arr[i] = input.nextInt();
  16.  
  17.             for(j = 2; j< arr[i]; j++)
  18.            {
  19.  
  20.                if(arr[i] % j == 0)
  21.                {
  22.                    count++;
  23.                    break;
  24.  
  25.                }
  26.            }
  27.             if(count == 0)
  28.             {
  29.                 System.out.printf("%d is a prime number\n",arr[i]);
  30.             }
  31.             else
  32.             {
  33.                 System.out.printf("%d is a not prime number\n",arr[i]);
  34.             }
  35.             count =0;
  36.         }
  37.  
  38.  
  39.     }
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement