Computer Science, asked by dasdharam0959, 4 months ago

java program to find prime number between 10 and 100​

Answers

Answered by keyboardavro
0

Answer:

Explanation:

Using Static Method

1) A prime number is a number which has no positive divisors other than 1 and itself.

2) We are finding the given number is prime or not using the static method primeCal(int num). For loop iterates from i=0 to i=given number, if the remainder of number/i =0 then increases the count by 1. After all the iterations, if count=2, then that number is a prime number.

Find Prime Numbers Java Program 1 To NJava

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

import java.util.Scanner;

class Prime

{

public static void main(String arg[])  

{

 

              System.out.println("Enter a number ");

Scanner sc=new Scanner(System.in);

int n=sc.nextInt();

primeCal(n);

}

  static void primeCal(int num)

  {

int count=0;

for(int i=1;i<=num;i++)

{

   if(num%i==0)

   {

        count++;          

   }

}

if(count==2)

       System.out.println("prime number ");

else

System.out.println("Not a prime number ");        

  }  

}

Answered by priyanka457931
0

Answer:

search it on google that will helpful

Similar questions