Check if given number is Prime Number | Java

Поділитися
Вставка
  • Опубліковано 7 січ 2025

КОМЕНТАРІ •

  • @aarulmozhinandhini1540
    @aarulmozhinandhini1540 3 роки тому +93

    I request u to post more videos like this....thanks to you i am able explain the logic clearly in my TCS interview 😁 and also got selected...thank you so much bro❤️

    • @BTechComputerScience
      @BTechComputerScience  3 роки тому +15

      Hey Congratulations, knowing someone has been blessed because of my videos makes me so happy.
      Thank you so much for taking the time to comment.

    • @BTechComputerScience
      @BTechComputerScience  3 роки тому +16

      I am caught up with my work, but u just inspired me to make more videos.

    • @aarulmozhinandhini1540
      @aarulmozhinandhini1540 3 роки тому +3

      @@BTechComputerScience its my pleasure ❤️

    • @aarulmozhinandhini1540
      @aarulmozhinandhini1540 3 роки тому +7

      @@BTechComputerScience i hope ur videos will be helping a lots of people....ur way of explaining is more clear and easy to understand...so please consider this to add more videos in ur channel 😊

    • @BTechComputerScience
      @BTechComputerScience  3 роки тому +4

      @@aarulmozhinandhini1540 I will surely try

  • @sondosalfukaha4221
    @sondosalfukaha4221 3 роки тому +5

    My university & my private course didn't explain it in a good way so I don't understand anything until seeing this video, a lot of thanks, man.

  • @honeyb9698
    @honeyb9698 3 роки тому +4

    So crisp and to the point explanation...Thank yoouu!

  • @sowmyamahadev18
    @sowmyamahadev18 Рік тому +1

    Thankyou. Fully understood. Keep posting vedios on Java. Simply easy to understand the way you teach. All is well.

  • @TheMatrixOwl
    @TheMatrixOwl 2 роки тому +6

    Thank you so much. You simulated the logic on paper and that made me understand it better. Keep it up!

  • @kaveridhore4398
    @kaveridhore4398 2 роки тому +1

    I referred so many videos for this program. After watching yours my doubt got fully solved. Thankyou so much.

    • @proxy5061
      @proxy5061 2 роки тому

      Yess if(n == 0 || n == 1){
      It's not a prime }
      Else
      { The vedio logic , the condition inside for loop must be n/2 } for loop ➿ condition is n/2

  • @Shruttiiiiii
    @Shruttiiiiii Рік тому +1

    Your channel deserves more Recognition 👍
    Plz do post more videos

  • @kunalkheeva
    @kunalkheeva 2 роки тому

    Bruh, you don’t know how many videos i watched for it, and this one is the simplest. ❤️❤️

  • @badrinarayanans355
    @badrinarayanans355 2 роки тому

    Thankyou for explaining prime number concept in a clear manner.

  • @re417k.nagasri8
    @re417k.nagasri8 3 роки тому +3

    Very simple approach,, tqq broo

  • @GamingBusterOneAndOnly
    @GamingBusterOneAndOnly 2 роки тому

    Really the simplest explanation everrr

  • @SiriSha-mq3lv
    @SiriSha-mq3lv 6 місяців тому

    Honestly the best explanation ever broo

  • @diamomd514
    @diamomd514 3 роки тому +1

    Very good and quiet ... Keep doing... 👍👍👍

  • @awesomejesus9509
    @awesomejesus9509 Місяць тому +1

    May i know why did you start the for loop from 2 ? Because as per index its start from 0 so its supports to be 1 i mean for (int i=1)

  • @sharannarsinginsb
    @sharannarsinginsb Рік тому

    Thank you so much it was really helpful. Appreciate your effort!👏

  • @tejalycan1772
    @tejalycan1772 Рік тому

    Thank you so much for clearly explaining the topic.. Please upload more videos

  • @divya.s.s1688
    @divya.s.s1688 7 місяців тому

    Super explanation to easy way of coding tq😊

  • @arpan_here3362
    @arpan_here3362 Місяць тому

    you should include another condition if the n is less than 2, then it should also print false. this for loop should be in else part. think about all kind of test cases.

  • @bhumighutke5997
    @bhumighutke5997 8 місяців тому

    Thank you so much ❤ You make it look so easier....

  • @karthikpranav2406
    @karthikpranav2406 3 роки тому +1

    thank you so much because of you I got the confidence to code easily :)

  • @suchi557
    @suchi557 2 роки тому +1

    Thank you so much sir it's helping me lot and now program Is very easy to me when u explained it clearly..

  • @vinoth9891
    @vinoth9891 3 роки тому

    Very simple and easy tq brother

  • @abidhazratzai1260
    @abidhazratzai1260 7 місяців тому

    Very clear explanation thank you

  • @bharadwaj25
    @bharadwaj25 Рік тому

    Thank you very much, you explained it in detail.

  • @BrainSparksMA
    @BrainSparksMA 3 роки тому +5

    Sir please make more videos on same topic like Palindrome number , angstrom number , factorial....
    You explain very good ❤️❤️❤️😀

  • @ravikantgaikwad5470
    @ravikantgaikwad5470 2 роки тому

    I request u to post more videos like this...thank you so much ❤

  • @rahulbhagwat4010
    @rahulbhagwat4010 2 роки тому

    this was the best explanation

  • @fraoulmassresha6639
    @fraoulmassresha6639 3 роки тому

    nice hand writing , like your font ..

  • @hemrajpatil782
    @hemrajpatil782 3 роки тому +1

    very nice sir. it looks very easy now.

  • @godson924
    @godson924 2 роки тому +2

    what if we take n =2 then 2%2 = 0 so will it not give output as not prime

  • @ritikakumbar6670
    @ritikakumbar6670 3 роки тому

    Superb explanation sir got it very well

  • @k.v.prabhu1860
    @k.v.prabhu1860 3 роки тому

    So many website theri use for loop( i=

  • @MrFars502
    @MrFars502 3 роки тому

    Thanks man you made it clear :)

  • @khushbusahani579
    @khushbusahani579 Рік тому

    Thankyou so much now I can clearly understand how to print prime no. What's the logic behind this program ☀️💯

  • @dhanashreesuryawanshi9650
    @dhanashreesuryawanshi9650 3 роки тому

    Thank You Bro.. you made it really simple

  • @Laundpana__
    @Laundpana__ 2 роки тому

    Thank you so much. you explained it in a beautiful and easy way.

  • @supriyagandham9604
    @supriyagandham9604 3 роки тому

    Helpful video tq sir 👍

  • @kathimahesh2492
    @kathimahesh2492 2 роки тому

    Super bro nice teaching

  • @MadhuSudhan-um2lm
    @MadhuSudhan-um2lm 2 роки тому

    beautiful answer but there are one mistake bro , if you are entered n = 1; output is true , this is wrong step

  • @saleemsadat6557
    @saleemsadat6557 3 роки тому +1

    good explanation. However, your formula will disregard negative numbers. For example if you put -11, it will print true. But we know minus 11 is not prime.

    • @BTechComputerScience
      @BTechComputerScience  3 роки тому

      Thanks for ur input, a 'if' statement before the loop to check input criteria would prevent it. Yes I didn't cover all test cases. Just the basics

    • @chandandastanti9346
      @chandandastanti9346 3 роки тому

      Before for loop add one if(n

  • @himanshujha3495
    @himanshujha3495 3 роки тому +1

    cool stuff, really cool stuff

  • @mr.badluck9521
    @mr.badluck9521 2 роки тому +1

    If we take 1 as input then it is showing true as a prime number but 1 is not prime number sir so it should be false at the output .

  • @salehmsf2311
    @salehmsf2311 Рік тому

    Good work💯

  • @girlstjohnian
    @girlstjohnian 3 роки тому +3

    Bro you pick up such good topics for your video, others just explain the concept and go forth, but here, you know like literally this question came in my exam, and coz of you! I got full marks!!

  • @nandalalsingh8082
    @nandalalsingh8082 3 роки тому

    U are the unique one sir
    I could able to understand the concept very deeply
    Thank you sir very much❤️❤️❤️❤️❤️

  • @40_shreyanbanerjee28
    @40_shreyanbanerjee28 3 роки тому

    Thanks.. but the output should be a little bit more specified !

  • @jaganjagan7958
    @jaganjagan7958 3 роки тому +3

    I think We can't find 2 as a prime number by this program..please do check with 2

    • @ruksanashaik2692
      @ruksanashaik2692 2 місяці тому

      In that case we have to check (flag && n>1)i.e 2>1 then 2 is a prime number

  • @gaddamprudhvi9737
    @gaddamprudhvi9737 2 роки тому

    nice explanation

  • @PraveenKumar-uj2ih
    @PraveenKumar-uj2ih 3 роки тому

    Simple Explanation

  • @keertiar1922
    @keertiar1922 3 роки тому

    Can you do programs and its output for all basic programs in java and also of different way of approaching.......

  • @moni6468
    @moni6468 Рік тому

    what will be the output for 1 and 2 ?

  • @hussainbasha3794
    @hussainbasha3794 2 роки тому

    Good explanation

  • @kraviteja3784
    @kraviteja3784 Рік тому

    bro why did you used util package . Can you please explain

  • @karthickmurugan9260
    @karthickmurugan9260 Рік тому

    Bro make video for how to trace out the program !

  • @KD_Doss
    @KD_Doss 3 роки тому

    Very very thank you sir...

  • @malavikasadasivan8291
    @malavikasadasivan8291 3 роки тому

    What is the output if n=4 can you show

  • @varunshadow8588
    @varunshadow8588 3 роки тому +1

    Super bro ❤️

  • @ramyar993
    @ramyar993 6 місяців тому

    why for loop i starts from 2? i refers to index right?

    • @BTechComputerScience
      @BTechComputerScience  6 місяців тому

      @@ramyar993 no, here it's not index, logic to finding prime number starts from 2, we first eleminate all 2's multiple, then eleminate 3's multiple and so on...

  • @vlogman5657
    @vlogman5657 2 роки тому

    thanks man! but the package prime; is really hitting me i dont get it right on blue j please respond fast

  • @Moonart.shorts
    @Moonart.shorts 3 роки тому

    Thank you❣️

  • @chiranjeevinarada1704
    @chiranjeevinarada1704 Рік тому

    Bro Please do video on SQL queries plz plz

  • @NaveenKumar-oc8bz
    @NaveenKumar-oc8bz 3 роки тому +1

    dear sir;
    i got revese output Which means that which are all prime number that show all false ,which are all not prime number that show true

    • @NaveenKumar-oc8bz
      @NaveenKumar-oc8bz 3 роки тому +1

      please explain sir
      i have confusion

    • @BTechComputerScience
      @BTechComputerScience  3 роки тому +1

      Mayb u r changing ur boolean variable wrongly, please check with ur boolean variable and where u r making it false or true... if still u r unable to fix it, post ur code in the comment, I ll help u out😊

    • @NaveenKumar-oc8bz
      @NaveenKumar-oc8bz 3 роки тому +1

      public class PrimeNum
      {
      public static void main(String[] args)
      {
      int n=7;
      boolean prime = true;
      for(int i=2;n>i;i++)
      {
      if(n%i==0)
      prime=false;
      break;
      }
      System.out.println(prime);
      }
      }
      this my code but it work wrong for me sir .i got confusion .please Explain me sir

    • @BTechComputerScience
      @BTechComputerScience  3 роки тому +1

      @@NaveenKumar-oc8bz ur break statement should be inside 'if' ... u missed the '{' and '}'
      Since ur break statement is inside for loop and not the 'if' statement, ur loop is breaking at first iteration.

    • @NaveenKumar-oc8bz
      @NaveenKumar-oc8bz 3 роки тому +1

      Thank you lot sir thank sir thank for ur explanation. Keep rocking sir i will support you sir i will share ur video to frd also

  • @niranjanravichandran8931
    @niranjanravichandran8931 Рік тому

    Bro what happens if I give n = 2?

  • @shidlingaswamy4044
    @shidlingaswamy4044 2 роки тому

    Bro good explanation.
    But 0 and 1 are not prime numbers if I give input as 1 or 0 for above program it will be printed as True. so please correct it

    • @BTechComputerScience
      @BTechComputerScience  2 роки тому +2

      I have explained at basic level, I have not solved the edge test cases, students should identify the edge test cases like u did and try to solve it. That's how we learn!

    • @shidlingaswamy4044
      @shidlingaswamy4044 2 роки тому

      @@BTechComputerScience K Thank you

  • @quantumapex4897
    @quantumapex4897 3 роки тому

    Tomorrow I have exam thank you sir for your effort🙏

  • @likky1139
    @likky1139 Рік тому

    Bro screen sarriga kanipinchadam ledhu and voice vinipinchadam ledhuu broh..

  • @Berrybooo
    @Berrybooo Рік тому

    but 2 is considered as a prime number the code will not be accurate here

  • @JAYARAMANca
    @JAYARAMANca 2 роки тому

    In case of 15 is not eligible for this method

  • @EDIT_X_AI
    @EDIT_X_AI 2 роки тому

    Bro your code go wrong if you input 2

  • @sallyxx23
    @sallyxx23 3 роки тому

    Thanks 😊

  • @vaibhavkumar4951
    @vaibhavkumar4951 2 роки тому

    bhai ye programme 2 ke liye fail ho jaega .......isme extra condition add krni pdegi

  • @rajeshkrishna1422
    @rajeshkrishna1422 Рік тому

    Sir can u please explain me kaprekar number?

  • @gaurav1005
    @gaurav1005 3 роки тому

    why we are running it from i=2 in for loop ?

    • @BTechComputerScience
      @BTechComputerScience  3 роки тому +3

      Since all numbers are divisible by 1, we are avoiding it to save some computational time.
      Also the given number will always be divisible by 1 and N and we need not care, all we have to see is if any other between 1 and N divides N to prove its NOT PRIME.

    • @gaurav1005
      @gaurav1005 3 роки тому

      @@BTechComputerScience thank you soo much sir

  • @dhanushcheni9480
    @dhanushcheni9480 2 роки тому

    In.. Your code we take... 2 then.. Its show not prime.. Number but 2 is prime number... Know... Then.. What we do

    • @BTechComputerScience
      @BTechComputerScience  2 роки тому

      Think about the logic, I know u can solve it! I just gave the basic logic for the program 😊

  • @ShashiAthram613-s2d
    @ShashiAthram613-s2d Рік тому

    sir why you can not take 9
    then u will took 9 it will print is a prime
    but it is not a prime

  • @mithank2666
    @mithank2666 3 роки тому

    thank you so much

  • @debaduttasahu9917
    @debaduttasahu9917 Рік тому

    great sir

  • @HR-pz7ts
    @HR-pz7ts Рік тому

    Codechef says this approach is wrong

  • @LYJManchesterUnited
    @LYJManchesterUnited 3 роки тому

    if you enter 0 or 1 it says it's a prime number

    • @BTechComputerScience
      @BTechComputerScience  3 роки тому +2

      It's great that u have noticed this, 0 and 1 are neither prime nor composite, for beginner level this program is fine.
      I really appreciate it, after roughly 5.8k views, u are the first person to notice.
      Just add this before the 'for' loop
      if(n == 0 || n == 1)
      {
      System.out.print("Neither prime nor composite");
      System.exit(0);
      }

  • @thesharks4676
    @thesharks4676 3 роки тому

    And then put the video for sum of primenumber ina given sequence

  • @sweetani9378
    @sweetani9378 Рік тому

    Okay bro check n=2

  • @roggamerg531gt
    @roggamerg531gt 2 роки тому

    what about 0 and 1

    • @proxy5061
      @proxy5061 2 роки тому

      Yess if(n == 0 || n == 1){
      It's not a prime }
      Else
      { The vedio logic , the condition inside for loop must be n/2 }

  • @programmerhub824
    @programmerhub824 2 роки тому

    0 and 1 ke case me fail ho jayega yeh program

    • @proxy5061
      @proxy5061 2 роки тому

      Yess if(n == 0 || n == 1){
      It's not a prime }
      Else
      { The vedio logic , the condition inside for loop must be n/2 }

  • @bindureddy2885
    @bindureddy2885 3 роки тому

    Nice explanation but video is not getting clear

    • @BTechComputerScience
      @BTechComputerScience  3 роки тому

      Thanks and sorry about that! Maybe its a little better at higher resolution.

  • @Ayush-onetime
    @Ayush-onetime 3 роки тому

    9 is not a prime number because it's multiple by 3, 1, 9..

  • @offthehook5042
    @offthehook5042 2 роки тому

    I want with inheritance

  • @anjeshwar1
    @anjeshwar1 Рік тому

    this program explains even or odd not prime. Give input as 9,15 it gives true but 9,15 are not prime numbers.
    sorry to say, check the programs with different inputs and upload bro. Most people doesn't checks it and follows the programs blindly.

  • @otmanehamad-j5n
    @otmanehamad-j5n 18 днів тому

    Love you

  • @sulaimansha6189
    @sulaimansha6189 3 роки тому

    What if number is 2

    • @BTechComputerScience
      @BTechComputerScience  3 роки тому

      Since 2 is divisible by 1 and the number itself (2), it is a prime number :)

    • @giridatta1525
      @giridatta1525 3 роки тому

      how to pass n=2 into loop?

  • @durgaprasadduvvu1781
    @durgaprasadduvvu1781 3 роки тому

    bro 9 is not prime 1 3 9

  • @janasenakonaseema9339
    @janasenakonaseema9339 Рік тому

    java basic

  • @omkaryadav7445
    @omkaryadav7445 Рік тому

    OG❤

  • @hodophilenafis3207
    @hodophilenafis3207 3 роки тому

    raza sir

  • @WolfPaul
    @WolfPaul 3 роки тому

    wow.

  • @crazyeditor1782
    @crazyeditor1782 Рік тому

    😜

  • @shaikhmerchant7625
    @shaikhmerchant7625 4 роки тому

    Sir plz provide your email

  • @rudranrock7658
    @rudranrock7658 3 роки тому

    🤙💫

  • @steven-g2t
    @steven-g2t 17 днів тому +1

    bro have pet crows

  • @rehanhussan
    @rehanhussan 2 роки тому

    System.out.println("Thanks");

  • @Ayush-onetime
    @Ayush-onetime 3 роки тому +5

    9 is not a prime number because it's multiple by 3, 1, 9..