This is a java program to find prime number. it find a number is prime or not .
prime number is a number which is divisible by one or that number not others.
Source Code:
- public class PrimeNumber {
- public static void main(String[] args) {
- try (Scanner input = new Scanner(System.in)) {
- int i,num,count = 0;
- System.out.println("Enter the positive number:");
- num = input.nextInt();
- for(i=2;i<num;i++) {
- if(num%i==0) {
- count++;
- break;
- }
- }
- if(count==0)
- System.out.println("This is prime number.");
- else
- System.out.println("This is not prime number.");
- }
- }
- }
Output:
Enter the positive number:5This is prime number.Enter the positive number:153This is not prime number.
0 comments:
Post a Comment