Computer Science, asked by Jaisinghal3625, 5 months ago

Write a program in Java to read two numbers and display all the prime numbers between these numbers.

Answers

Answered by DEV00798
0

Answer:

ya sure here is your answer and ya please mark me as brainliest most of  the question's which are related  to this computer type question's are answered by me

Explanation:

import java.util.Scanner;  

public class PrimeExample4 {  

  public static void main(String[] args) {  

      Scanner s = new Scanner(System.in);  

      System.out.print("Enter the first number : ");  

      int start = s.nextInt();  

      System.out.print("Enter the second number : ");  

      int end = s.nextInt();  

      System.out.println("List of prime numbers between " + start + " and " + end);  

      for (int i = start; i <= end; i++) {  

          if (isPrime(i)) {  

              System.out.println(i);  

          }  

      }  

  }  

  public static boolean isPrime(int n) {  

      if (n <= 1) {  

          return false;  

      }  

      for (int i = 2; i <= Math.sqrt(n); i++) {  

          if (n % i == 0) {  

              return false;  

          }  

      }  

      return true;  

  }  

}  

Similar questions