Print all Prime Numbers till N - Solution | Java Foundation Course | Lecture 13

preview_player
Показать описание
Question Name:
Print all Prime Numbers till N

Question Link:

Question Statement:
1. You've to print all prime numbers between a range.
2. Take as input "low", the lower limit of range.
3. Take as input "high", the higher limit of range.
4. For the range print all the primes numbers between low and high (both included).

--------------------------------------------------------------------------------------------------------------------------------------------------------------


--------------------------------------------------------------------------------------------------------------------------------------------------------------

Pepcoding has taken the initiative to provide counselling and learning resources to all curious, skillful and dedicated Indian coders. This video is part of the series to impart industry-level web development and programming skills in the community.

We also provide professional courses with live classes and placement opportunities.

DSA Level 1 and Level 2

We are also available on the following social media platforms :-

HAPPY PROGRAMMING!
Pep it up.....

Hashtags

#java #javafoundation #primenumbers
Рекомендации по теме
Комментарии
Автор

It feels best when you solve answer before coming to answers video🥰

pradyumnsingh
Автор

Sir we can further optimize this code by only checking for odd numbers as all even numbers except 2 can never be prime

jagritbudhiraja
Автор

sir your way of explaination is always helpful.

satyamgupta
Автор

sumit sir, your way of explaining is awesome ❤️

ayushajayuzfmvwfenu
Автор

If there is no lower bound check for sieve of eratosthenes.

tushar
Автор

Sir prime number print karane ke liye koi or approach hai?
Like ki hum phle, if number is divisible by 2 hai toh use escape kr de

somyasinghal
Автор

In the second for loop div * div <= n if I write div<=n/2 is this also correct? Please resolve this doubt

honeysungra
Автор

sir agar int count=0; ko for loop sa upar ya bahar likte hai toh wrong answer kyu aa rha ha hai

umang
Автор

Sir hum (count ==0) ke bjae (count==1) likhenge na because sir ek baar toh div divide krega hi break hone se pehle..

GrowwithVivek
Автор

I am still unable to understand as to why we need two/2 FOR LOOPS and why cannot (or rather what happens if we use only one/1 FOR LOOP) we achieve the solution using only one/1 FOR LOOP?
Could someone educate my ignorance? Thanks in advance.

sandeeptanjore
Автор

// This approach is 3 times faster approach than square root approach
public static boolean isPrime(int num){
if(num<=1){
return false;
}
if(num==2||num==3){
return true;
}
if(num%2==0||num%3==0){
return false;
}

for(int i=5;i*i<=num;i=i+6){
if(num%i==0||num%(i+2)==0){
return false;
}
}

return true;
}

divyanshutripathi