Write a Java Program to display all prime numbers in a given range by Mahesh Huddar

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 ต.ค. 2024

ความคิดเห็น • 7

  • @md.sabbirhosen5702
    @md.sabbirhosen5702 ปีที่แล้ว +1

    Thanks sir, Excellent Explanations but it does not work for 0,1 or any negative numbers! How can it may solved?

    • @AjayKumar-sg7dd
      @AjayKumar-sg7dd ปีที่แล้ว +1

      0 and 1 are not prime numbers.

    • @kyawkyawaung2362
      @kyawkyawaung2362 ปีที่แล้ว

      Firstly, thanks a lot for this excellent explanation!.
      based on this tutorials, I solved in this way to exclude 0,1 and negative minimum input for my exam and output for primeCount. See the code for your info.
      public class PrimeNumberBtwStartAndEnd {
      public static void main(String[] args) {
      primeCount(10, 30);
      primeCount(11, 29);
      primeCount(20, 22);
      primeCount(1, 1);
      primeCount(5, 5);
      primeCount(6, 2);
      primeCount(-10, 6);
      }
      public static void primeCount(int start, int end) {
      int count = 0, flag = 0;
      for (int n = start; n

    • @MrW4gyu
      @MrW4gyu ปีที่แล้ว

      Math.abs

    • @sulaimandanish4561
      @sulaimandanish4561 ปีที่แล้ว

      will it work for 2?@@AjayKumar-sg7dd

    • @gurushinde9694
      @gurushinde9694 ปีที่แล้ว +1

      you can add an if block within the first for loop to check for 0 and 1

  • @skv292002
    @skv292002 2 หลายเดือนก่อน

    How to find range between nth prime number positions