Prime Number Program in Java #62

  Рет қаралды 66,397

Alex Lee

Alex Lee

Күн бұрын

$1,000 OFF ANY Springboard Tech Bootcamps with my code ALEXLEE. See if you qualify for the JOB GUARANTEE! 👉 bit.ly/3HX970h
This is the code to find prime numbers in a range in java! ✅Hopefully, this helps you with your assignments or with just practice!
👑Start practicing now with 10 free java programs - alexlorenlee.com/
🌅 Source Code - github.com/alexlorenlee/JavaT...
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 :)
Do you want to learn how to write java code from scratch, in Java? Check out my Java Tutorial For Beginners: • Coding For Beginners I...
Was this program able to help you understand finding prime numbers between a range?
Full Java Tutorial For Beginners Playlist: • Full Java Course by Al...
Free Tips: bit.ly/3U6HXcb
Disclosure: The Springboard link provided is linked to my affiliate account & supports the channel.
~
Alex Lee

Пікірлер: 45
@alexlorenlee
@alexlorenlee 8 ай бұрын
If you’re new to programming but want a career in tech, I HIGHLY RECOMMEND applying to one of Springboard’s online coding bootcamps (use code ALEXLEE for $1,000 off): bit.ly/3HX970h
@CollidaCube
@CollidaCube 3 жыл бұрын
gotta love how fast programs can go. one million numbers in 16 seconds! holy crap!
@vishy
@vishy 4 жыл бұрын
That was an awesome program ... definitely one of the harder ones i found, but i got there in the end!
@somename3424
@somename3424 2 жыл бұрын
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
@mattsmith6828
@mattsmith6828 3 жыл бұрын
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".
@sirmohammed772
@sirmohammed772 3 жыл бұрын
Thank you so much Alex 🙏🏼
@Abhaykumar-pi8ng
@Abhaykumar-pi8ng 3 жыл бұрын
Thank u so much it's the exact video that I was looking for....
@asadbekbozorov5714
@asadbekbozorov5714 3 жыл бұрын
Thank You!
@strangeussser
@strangeussser 3 жыл бұрын
THANK YOU SM. btw your hands are too fast 😭💗 i'm trying to reach this level in writing
@markrosadino2702
@markrosadino2702 4 жыл бұрын
I love your keyboard. Where can I get one?
@yyyyyyyyyyy1988
@yyyyyyyyyyy1988 2 жыл бұрын
Great thx alot.
@jadrienclemente8157
@jadrienclemente8157 4 жыл бұрын
Thank you you saved my life crying emoji
@ChMaDutton
@ChMaDutton 2 жыл бұрын
is there a video out there about finding the largest number?
@samayra0012
@samayra0012 3 жыл бұрын
what to do is if I want to print a statement only once I while using a for loop???
@66albukhari
@66albukhari 3 жыл бұрын
what is the type of your keyboard?
@ghettoasfuckxp
@ghettoasfuckxp 5 жыл бұрын
Can u do How much Pilot G Tec c4 can write
@ahavlogsandfashions3994
@ahavlogsandfashions3994 3 жыл бұрын
how to write prime numbers in revers order
@user-xe5uc4ex3u
@user-xe5uc4ex3u 3 жыл бұрын
Where you get that keyboard from ?
@sungnguyen3920
@sungnguyen3920 3 жыл бұрын
how do you print just 10 prime number per line
@ankush_in_sync5998
@ankush_in_sync5998 2 жыл бұрын
Thank yōu
@vinothr5024
@vinothr5024 3 жыл бұрын
Why using n/2
@gabrielcantu3209
@gabrielcantu3209 5 жыл бұрын
Hey I was just wondering, How would you make a loop using strings?
@funlife5946
@funlife5946 Жыл бұрын
I dont think its possible
@michellereckling7495
@michellereckling7495 2 жыл бұрын
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!
@kakashi99908
@kakashi99908 2 жыл бұрын
Simply put, you actually cant call a non-static method inside a static method. So in this case the main method is always static here he has no choice but to findPrimes static. He would have to make an entirely new class then create an object of it like a class Called PrimeCalculation that has the non-static method findPrimes. Then he would have to do PrimeCalculation.findPrimes(1,100); inside of this file he is showing obviously that is a lot of work for no benefit. Additionally, Static means its not part of an object meaning it can be used right away without making an object. So pros of static methods: Pros: Easier to use since you don't need to use objects and other classes, better for simple things, sometimes you only want to do a simple task and not have it a part of an object Cons: You can't use it on object instances, kind of like a 1 time use thing(the other times you use it essentially get overridden) Hence this kind of defeats the purpose of object oriented programming. Although for simple demonstrations it does not matter much :)
@mattsmith6828
@mattsmith6828 3 жыл бұрын
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; }
@shotx333
@shotx333 2 жыл бұрын
Great video, just: if (n == 1) { return false; }
@ninjacat1653
@ninjacat1653 4 жыл бұрын
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.
@aksel8034
@aksel8034 2 жыл бұрын
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 ?
@ozzDeveveloperOpenForWork
@ozzDeveveloperOpenForWork Жыл бұрын
so you put nothing for n, so then how does the while loop run? n is never defined
@thelionhour8907
@thelionhour8907 3 жыл бұрын
Love from india
@scaramoucheysimp
@scaramoucheysimp 3 жыл бұрын
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
@traviss7740
@traviss7740 2 жыл бұрын
for (int>2)
@shivpatel8288
@shivpatel8288 3 жыл бұрын
why n/2 ?
@dinakaremmanuel1723
@dinakaremmanuel1723 3 жыл бұрын
n/2 is nearly the largest factor of n and there r no more factors after that For example: if n=32 it's largest factor is 32÷2=16. There's no point in checking the numbers after 16
@omursahin7280
@omursahin7280 4 жыл бұрын
1 is not a prime number, there is an error with the code.
@user-mn3iq2cs9n
@user-mn3iq2cs9n 4 жыл бұрын
Hey Omur, you are correct. One is not a prime number, though it meets the criteria. All we have to do is put an extra line of code in, a conditional, just before the while loop. if (n == 1) prime = false; Then all is well.
@maelstrom57
@maelstrom57 3 жыл бұрын
@@user-mn3iq2cs9n Or: if (prime && n != 1) instead of just: if (prime)
@chinecheremejikeme6209
@chinecheremejikeme6209 3 жыл бұрын
i'm tryin to do it to 500,000, but nothing running
@chinecheremejikeme6209
@chinecheremejikeme6209 3 жыл бұрын
from 2 to 500,000
@szirakiakos4334
@szirakiakos4334 3 жыл бұрын
@@chinecheremejikeme6209 it takes a while for the program to be executed with such big numbers.
@walex1281
@walex1281 Жыл бұрын
It's datatype will be change u have to use long then instead of int
@regomar
@regomar 7 ай бұрын
1 isn't a prime number
@ghettoasfuckxp
@ghettoasfuckxp 5 жыл бұрын
.
@mustafadurmus9431
@mustafadurmus9431 Жыл бұрын
one is not a prime number :)
Palindrome Program In Java Tutorial #63
9:50
Alex Lee
Рет қаралды 101 М.
Can You Draw A PERFECTLY Dotted Line?
00:55
Stokes Twins
Рет қаралды 85 МЛН
WHO DO I LOVE MOST?
00:22
dednahype
Рет қаралды 79 МЛН
Пробую самое сладкое вещество во Вселенной
00:41
Find Prime Numbers In Java - Full Walkthrough with Source
13:17
Coding with John
Рет қаралды 35 М.
Fibonacci Series In Java With Recursion - Full Tutorial (FAST Algorithm)
15:11
#25 Python Tutorial for Beginners | Prime Number in Python
4:11
For Loop Pattern Program In Java #25
15:49
Alex Lee
Рет қаралды 165 М.
Try Catch Java Tutorial #46
11:05
Alex Lee
Рет қаралды 216 М.
HashMap Java Tutorial #50
11:42
Alex Lee
Рет қаралды 410 М.
Java Program #10 - Palindrome Number in Java
10:03
Programming For Beginners
Рет қаралды 10 М.
Can You Draw A PERFECTLY Dotted Line?
00:55
Stokes Twins
Рет қаралды 85 МЛН