Computer Science, asked by SharanyaBanerjee, 8 months ago

WAP in java to print all the prime numbers in a range from m to n where m <n and both are positive integers using scanner class​

Answers

Answered by hoangmustang
1

Answer:

CHECK OUT MY SOLUTION

package newPackage;

import java.util.*;

public class primes {

public static void main(String[] args) {

 

Scanner input = new Scanner(System.in);

System.out.println("Please enter m number: ");

int m = input.nextInt();

System.out.println("Please enter n number: ");

int n = input.nextInt();

for(int i = m; i <= n; i++) {

if(checkPrime(i)==false)

 System.out.println(i);

}

}static boolean checkPrime(int number) {

 boolean flag = false;

       for(int i = 2; i <= number/2; ++i){

           // condition for nonprime number

           if(number % i == 0)

           {

               flag = true;

               break;

           }

       }

       return flag;

   }

}

Explanation:

MARK ME BRAINLIEST!

Similar questions