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
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
India Languages,
4 months ago
English,
4 months ago
India Languages,
4 months ago
Business Studies,
8 months ago
Sociology,
8 months ago
Geography,
1 year ago
Computer Science,
1 year ago
English,
1 year ago