Prime Number Program in Java #62

preview_player
Показать описание

This is the code to find prime numbers in a range in java! ✅Hopefully, this helps you with your assignments or with just practice!

This prime number program in java can be tricky at first... But SURELY you'll get it :) If you followed along, congrats! You learned-by-doing!

I hope you enjoyed this prime number program in java! I like to have a nice mix of tutorials and actual projects for you all :)

Was this program able to help you understand finding prime numbers between a range?

Disclosure: The Springboard link provided is linked to my affiliate account & supports the channel.

~

Alex Lee
Рекомендации по теме
Комментарии
Автор

gotta love how fast programs can go. one million numbers in 16 seconds! holy crap!

CollidaCube
Автор

Instead of n/2, I think you could instead use the square root of 'n', rounded up (to the next integer) if the decimal value is greater than zero.
This is because any number that's bigger than the square root will have to be multiplied by a SMALLER number than the square root, in order for the product of these two numbers to equal the number in question.
Also, you can start the count at ONE, and then count by 2 (counting only odd numbers). So, instead of "i++", you would have "i+=2".

mattsmith
Автор

the face cam helps me keep focus, the keyboard cam helps to see exactly what youre doing and the shortcut cam is like a mini tip and tricks by itself. combine that with great videos like these and you got yourself a winning playlist for learning java basics

somename
Автор

That was an awesome program ... definitely one of the harder ones i found, but i got there in the end!

vishy
Автор

THANK YOU SM.
btw your hands are too fast 😭💗 i'm trying to reach this level in writing

strangeussser
Автор

Thank you you saved my life crying emoji

jadrienclemente
Автор

I love your keyboard. Where can I get one?

markrosadino
Автор

Thank u so much it's the exact video that I was looking for....

Abhaykumar-ping
Автор

public static boolean isPrime(final long n)
{
if (n == 2) return true;
if ((n < 2) || (n % 2 == 0)) return false;
for (long i = 3; i < (long) Math.floor(Math.sqrt(n)) + 1; i += 2)
{if (n % i == 0) return false;}
return true;
}

mattsmith
Автор

this is a great method but how would we account for the fact that 1 and 0 are not prime numbers? the method would return true for those integers otherwise

scaramoucheysimp
Автор

is there a video out there about finding the largest number?

ChMaDutton
Автор

Great video, just:
if (n == 1) {
return false;
}

shotx
Автор

Is there a video that explains why you made the method static? I am still struggling with when/why to use static methods. Thank you!

michellereckling
Автор

Hey I was just wondering, How would you make a loop using strings?

gabrielcantu
Автор

so you put nothing for n, so then how does the while loop run? n is never defined

ozzDeveveloperOpenForWork
Автор

what to do is if I want to print a statement only once I while using a for loop???

samayra
Автор

how to write prime numbers in revers order

ahavlogsandfashions
Автор

hi there, i tried to apply this in intellij and it refused to take start, end, ...and other namings....many errors in the code. anything better than this ?

aksel
Автор

1 is not a prime number, there is an error with the code.

omursahin
Автор

my professor gave us an exam and we all failed because she didnt teach a program that doesnt use import java.util.*Scanner;, and then the question is give atleast 3 examples and make a program that can detect the lowest number without using a scanner. I really need help and i dont know what to do.

ninjacat