0% found this document useful (0 votes)
4 views1 page

Check Prime

The document presents a Java program that checks if a given number is prime. It uses a loop to count the number of factors of the input number and determines if it is prime based on whether the count equals two. Key variables include 'n' for the user input, 'i' for iteration, and 'count' for tracking factors.

Uploaded by

98hwkb4rzt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Check Prime

The document presents a Java program that checks if a given number is prime. It uses a loop to count the number of factors of the input number and determines if it is prime based on whether the count equals two. Key variables include 'n' for the user input, 'i' for iteration, and 'count' for tracking factors.

Uploaded by

98hwkb4rzt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Program to enter a number and check if it is a prime

import java.util.*;

import java.io.*;

import java.lang.*;

//Importing Packages

public class CheckPrime //declaring cass

{ //opening braces of class

public static void main(String[]args) //declaring main methd

{ //opening braces of main method

int i,count=0; //declaring temporary variables

Scanner pa = new Scanner(System.in); //declaring scanner class

System.out.println("Enter the Number");

int n = pa.nextInt(); //inputing the number

for(i=1;i<=n;i++)

{ //opening braces of loop

if(n%i==0)

count++; //incrementing value of count by 1

} //closing braces of loop

if(count==2)

System.out.println("It is a prime number");

else

System.out.println("It is not a prime number");

}//closing braces of main method

VARIABLE DATA TYPE FUNCTION


n Integer To store the number entered by the user
i Integer To check the factors of the number
c Integer To count the number of factors

You might also like