Is a number Prime? - Solution | Java Foundation Course | Lecture 11

  Рет қаралды 107,107

Pepcoding

Pepcoding

Күн бұрын

Question Name:
Is a number Prime?
Question Link:
Question Statement:
1. You've to check whether a given number is prime or not.
2. Take a number "t" as input representing count of input numbers to be tested.
3. Take a number "n" as input "t" number of times.
4. For each input value of n, print "prime" if the number is prime and "not prime" otherwise.
-----------------------------------------------------------------------------------------------------------------------------------------------------------
Please consume this content on nados.io for a richer experience. It is necessary to solve the questions while watching videos, nados.io enables that.
NADOS also enables doubt support, career opportunities and contests besides free of charge content for learning. In this video, we discuss the solution of "Is a number Prime" problem. To understand the question, watch this video: • Is a number Prime? - Q...
--------------------------------------------------------------------------------------------------------------------------------------------------------------
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.
For better experience and well organized free resources visit -
We also provide professional courses with live classes and placement opportunities.
DSA Level 1 and Level 2
www.youtube.co...
Here is a roadmap to our Free study content and know more about our resources here -
We are also available on the following social media platforms: -
Facebook(Meta) - / pepcoding
Instagram - / pepcoding
LinkedIn - / pepc. .
Pinterest - / _c. .
Twitter - / pepcoding
KZbin (English Channel)- / @pepcodingprogrammingi...
Also take a look at our placement assistance - www.pepcoding....
HAPPY PROGRAMMING!
Pep it up.....
Hashtags
#java #javafoundation #isnumberaprime

Пікірлер: 99
@naushadalam5129
@naushadalam5129 2 жыл бұрын
🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂first time in life , maine real example ke sath time complexity smjh liya sir .aaj tak sirf books me hi pdhe the sir 🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏 thank you sir ......you are great 🤟
@mdzahidfaran7743
@mdzahidfaran7743 2 жыл бұрын
What an explanation. I have not seen this type of explanation on any other Java tutorial.
@akshatapawar32
@akshatapawar32 4 жыл бұрын
Best mentor ever.Thank you summit sir you are preparing us to think in all direction of problems with considering time complexity of questions.Thank you so much.
@Pepcoding
@Pepcoding 4 жыл бұрын
It's my pleasure
@bishalkeshri2168
@bishalkeshri2168 Жыл бұрын
Very truly said, he's the best mentor a student can ever have. Such a humble and down to earth celebrity he is❤❤🙏🙏.
@sarthaknikhal5540
@sarthaknikhal5540 4 жыл бұрын
Sir, please make videos on how to find time complexity. It's a humble request. I really understand your explanations, and that's the reason for this request. Thank you!
@Pepcoding
@Pepcoding 4 жыл бұрын
beta ab se kisi question mei miss nahi hogi. level2 se
@sarthaknikhal5540
@sarthaknikhal5540 4 жыл бұрын
@@Pepcoding ok, sir 👍
@aakankshajha2080
@aakankshajha2080 3 жыл бұрын
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=1;i
@sportsdata5018
@sportsdata5018 Жыл бұрын
Can I connect with you on LinkedIn?
@poojachoudhary4607
@poojachoudhary4607 Ай бұрын
How you get to know that T will do operations of 10 to the power 4 exactly ?
@nustagame25
@nustagame25 Ай бұрын
Problem statement
@shubhamaggarwal3823
@shubhamaggarwal3823 4 жыл бұрын
i loved the way u solved the question in pieces ....😍😍
@MadaraUchiha1706_
@MadaraUchiha1706_ 25 күн бұрын
If you guys starts loop from 2 then you should update if block(outside loop one) with if(sum==1) because if we are starting loop from 2 then sum value should only be increased 1 time because of itself...
@rahul_singh_rajput3292
@rahul_singh_rajput3292 2 жыл бұрын
I'll follow this dsa courSe 🙂🙂 the best way of teaching and explaining here 🙃 i ❤ it.. Pepcoding 😊😊
@Pepcoding
@Pepcoding 2 жыл бұрын
Glad you love the explanation, for better experience and well organised content sign up on nados.io and start learning.
@SCRIPTSAG
@SCRIPTSAG 4 жыл бұрын
Sir es tarike se socha nhi kabhi pahli bar lag rha hai ki coding hoti kya hai
@techeduidea2598
@techeduidea2598 2 жыл бұрын
Sir kuch set of question ka practice kara dijiye Time and Space Complexity par please
@AsmitaRana-qj3li
@AsmitaRana-qj3li 17 күн бұрын
Amazing ..sir .. You are the best
@ujjawalgupta98
@ujjawalgupta98 3 жыл бұрын
sir i am solving this question at the website currently with your exact solution..still it is showing 6/10
@Pepcoding
@Pepcoding 3 жыл бұрын
Beta, question dhng se pdo aur jo question main print krne k liye given h usse as it is print krna h.
@ishantsadhawani350
@ishantsadhawani350 3 жыл бұрын
@@Pepcoding Sir I am still facing the issue 2/5 test cases failed.(Runtime Error).
@shivam3387
@shivam3387 3 жыл бұрын
@@Pepcoding Sir, test cases me 10 ko as a prime print karne bola rha
@ishantsadhawani350
@ishantsadhawani350 3 жыл бұрын
@@Pepcoding Sir please help.🙌
@ankushgupta365
@ankushgupta365 3 жыл бұрын
try this code... import java.util.*; public class Main{ public static void main(String[] args) { Scanner scn = new Scanner(System.in); int t = scn.nextInt(); for(int i = 0; i < t; i++){ int n = scn.nextInt(); int div = 2; while(div * div n){ System.out.println("prime"); } else { System.out.println("not prime"); } } } }
@RobbyDongre
@RobbyDongre 3 жыл бұрын
Sir suppose if we are checking for number "1" . Answer prime ayga is approach see . Any solution for that ?
@Rohit-te9dr
@Rohit-te9dr 3 жыл бұрын
Thank you summit sir you are preparing us to think in all direction of problems with considering time complexity of questions.Thank you so much. but sir their is a small mistake in your program it gives 0 and 1 as prime
@Pepcoding
@Pepcoding 3 жыл бұрын
I am glad
@manish4275
@manish4275 4 жыл бұрын
Sir square root method ka Time complexity O(n) hai ki O(sqrt(n))? Also Sir, if our input number (n) is very very large, like 10 ^ 20, will the same code work? Assuming we used long long int or double.
@Pepcoding
@Pepcoding 4 жыл бұрын
This won't work for very large numbers. You will have to use Java Long. Complexity square root n ki hai.
@Dibakash
@Dibakash Жыл бұрын
Hi, you have not set a guard clause (for n == 0 or n == 1). The portal (pepcode) is accepting wrong codes that wrongly output 1 as prime. And it is rejecting correct codes. The failed test cases clearly show that for the input int 1, it is expecting output as prime (which is wrong as 1 isn't a prime number)
@Dibakash
@Dibakash Жыл бұрын
However, thanks for the wonderful concepts (specially the recursion series)
@Farhan-uo2ll
@Farhan-uo2ll Ай бұрын
❤️❤️thnku so much sir
@yubarajmohanty70
@yubarajmohanty70 2 ай бұрын
thank you sir
@lakshmipunugula2274
@lakshmipunugula2274 3 жыл бұрын
sir,can you please explain in english.
@himanshuaggarwal2445
@himanshuaggarwal2445 4 жыл бұрын
sir you teach best i loved it 👍
@Pepcoding
@Pepcoding 4 жыл бұрын
I am glad you liked it. I also hope that you are watching till end and trying to understand the what, how and especially why of the problem. If you like my efforts, I request a review g.page/Pepcoding/review?rc
@rohanrohan2758
@rohanrohan2758 2 жыл бұрын
If n=12, then count will increase as '1' ie count = 1. then how will the count will restore to '0' for the next input? Please answer.
@daaamn6414
@daaamn6414 2 жыл бұрын
Lol now I am also confused after reading this. Can you please explain the answer if u found it ?
@princetirkey8710
@princetirkey8710 2 жыл бұрын
Also if the number is 1 then also it is printing "Prime" but we know 1 is "not prime"
@princetirkey8710
@princetirkey8710 2 жыл бұрын
@@daaamn6414 After the internal loop terminate the count variable gets destroyed as it is local variable to external i loop , after this i++ a new count variable is created with count =0
@daaamn6414
@daaamn6414 2 жыл бұрын
@@princetirkey8710 Yeah thnx bro! Got it !!
@manikasunal7687
@manikasunal7687 3 жыл бұрын
You are one of the best teacher 🙌
@Pepcoding
@Pepcoding 3 жыл бұрын
Wow, thank you!
@StudyWithAnupam
@StudyWithAnupam 2 жыл бұрын
What is the use of Int Count ?
@simarjeetsingh6531
@simarjeetsingh6531 26 күн бұрын
+1
@shivamsetia4711
@shivamsetia4711 2 жыл бұрын
Can anyone explain how this code is working for number 15
@umang2049
@umang2049 3 жыл бұрын
Toh maine aapki prime no. Ki video dekhi or aage bhi follow kr rha hu toh sir kabse khud sa bnana aana chaiya ya aajaega?
@Pepcoding
@Pepcoding 3 жыл бұрын
Level 1 to yunhee niklega
@ojasgupta1189
@ojasgupta1189 2 жыл бұрын
Great sir !!!!
@th3graduate292
@th3graduate292 2 ай бұрын
it took time but i understood it very well.
@thiyageshkanna
@thiyageshkanna 3 жыл бұрын
Would be better if you teach in english!!!
@gokul6120
@gokul6120 4 жыл бұрын
Sir aap count kyo use kiye.
@Pepcoding
@Pepcoding 4 жыл бұрын
bhot sare tareeke hain. ye bhi to theik hai.
@RohitGupta-kl7je
@RohitGupta-kl7je 4 жыл бұрын
I run the same program it's saying for n .. Variable declaration is not allowed here
@rohitsorot5136
@rohitsorot5136 3 жыл бұрын
mne kal placement program wale batch me samja ye question but ab jake full clear hua app abhi bhi best pada rahe ho sumeet sir dont stop teaching please i want to study level 2 and 3 from you atleast if u dont have time make level 2 3 videos so i cant clear doubt in class i will saw the vides pleasse its a request i know sab teacher bht accha content bana rahe h bbut jse ape level 1 dal rakha h ese hi level 2 3 bhi slow and steady bana dijiye jara compare karo views ke apke content pe views kitne aate h....ese bh teachers h jinhone coaching centre khol liye but still vo khud bhi padate h
@pratikdeore7427
@pratikdeore7427 Жыл бұрын
Very helpful explanation :)
@KishanYadav-fn1gl
@KishanYadav-fn1gl Жыл бұрын
(√n) root nka concept nhi samja koi explain kar do
@NoOne-jl2ii
@NoOne-jl2ii 2 жыл бұрын
12 / 554
@rajdipdas1329
@rajdipdas1329 2 жыл бұрын
for the number 24 if we proceed with normal process then 2*12 and 12*2 is the same thing then why should we check so many times there is the huge wastage of time for that reason we have to go upto sqrt(n).
@Pepcoding
@Pepcoding 2 жыл бұрын
For better insight, visit nados.io, post your doubts, community will help you out there.
@snehasomnathe8802
@snehasomnathe8802 Жыл бұрын
Best Explanation, I have ever seen
@RaviVerma-pm6bx
@RaviVerma-pm6bx 4 жыл бұрын
You missed part when user entered one of the input number as 1 then this code will not show proper output. I think If(i!=1) outside your inner for loop is required.
@Pepcoding
@Pepcoding 4 жыл бұрын
1 is neither prime, nor composite. Hanji, alag se handle karna chaie tha.
@manishkumarprasad1911
@manishkumarprasad1911 4 жыл бұрын
you are right. but I think you don't see the constraints in the question that is (2
@travel2react567
@travel2react567 3 жыл бұрын
Best problem solving approach. aise to aaj tak kisi ne programming nahi samjhaya.
@umang2049
@umang2049 3 жыл бұрын
Sir abhi khud sa code nhi bn pa rha
@Pepcoding
@Pepcoding 3 жыл бұрын
Beta ye to shuru hai. Thode time baad bna paoge
@adityarenapure7397
@adityarenapure7397 4 жыл бұрын
sir where is our academy??
@Pepcoding
@Pepcoding 4 жыл бұрын
pitampura, delhi
@prathamdhiman764
@prathamdhiman764 3 жыл бұрын
Sir u didn't told us earlier about count and div
@Japanpreet
@Japanpreet 2 жыл бұрын
I didn't get it
@geetanegi2736
@geetanegi2736 3 жыл бұрын
Sir level 1 ka lia notes bnana jruri hai kya???????🇮🇳🔥😎🇮🇳
@Pepcoding
@Pepcoding 3 жыл бұрын
nhi to
@waseemqureshi3607
@waseemqureshi3607 Жыл бұрын
sir isme t kya krr rha hai
@bentennyson8923
@bentennyson8923 3 жыл бұрын
sir, please correct the test cases for this question.
@mr.nobody8365
@mr.nobody8365 2 жыл бұрын
*Completed*
@rock_213
@rock_213 2 жыл бұрын
Thank you so much sir❤
@nightcrusader5047
@nightcrusader5047 4 жыл бұрын
Damn good explanation sir
@brajesh2334
@brajesh2334 2 жыл бұрын
sir if input will be 1 then how to tackle it
@Pepcoding
@Pepcoding 2 жыл бұрын
For such queries sign up on nados.io and you can post your queries on community section of NADOS.
@shubhamaggarwal3823
@shubhamaggarwal3823 4 жыл бұрын
thank you sir 🙏🙏👍👍
@vedanthbaliga7686
@vedanthbaliga7686 4 жыл бұрын
Is this the sieve of eratosthenes algorithm?
@Pepcoding
@Pepcoding 4 жыл бұрын
Nope. But this is also optimizes somewhat.
@bhanupratapsingh5468
@bhanupratapsingh5468 4 жыл бұрын
Sumit Sir do you teach Python also?
@Pepcoding
@Pepcoding 4 жыл бұрын
Not now but we will cover it soon.
@deepakgauttam29
@deepakgauttam29 2 жыл бұрын
Sir n=1 per work nhi kar rha
@stayuptodate6441
@stayuptodate6441 2 жыл бұрын
just modify the condition as if (count == 0 && n!=1)
@yashkaushik8691
@yashkaushik8691 3 жыл бұрын
thanks soo much sir
@Pepcoding
@Pepcoding 3 жыл бұрын
Most welcome Beta and If you like our efforts, please upvote the comments written by the students about Pepcoding here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )
@yashgarg3373
@yashgarg3373 4 жыл бұрын
I Learned a new way to solve it... thank you sir..
@Pepcoding
@Pepcoding 4 жыл бұрын
Most welcome
@realigc8778
@realigc8778 3 жыл бұрын
Sir jab m coding vs code m kar rha tha toh usne scn ko close karne k liye bhi kha ... Esa kya ??
@Pepcoding
@Pepcoding 3 жыл бұрын
Beta, I regret to inform you that, I won't be able to answer/solve the personal doubts of each and every student over here. For clearing your doubts, you can join our community on telegram - t.me/pepcoding.
Pattern-1 | Solution | Java Foundation Course
15:10
Pepcoding
Рет қаралды 42 М.
Man Mocks Wife's Exercise Routine, Faces Embarrassment at Work #shorts
00:32
Fabiosa Best Lifehacks
Рет қаралды 6 МЛН
How do Cats Eat Watermelon? 🍉
00:21
One More
Рет қаралды 11 МЛН
Amazing Parenting Hacks! 👶✨ #ParentingTips #LifeHacks
00:18
Snack Chat
Рет қаралды 23 МЛН
L3. Check if a Number if Prime or not | Maths Playlist
7:10
take U forward
Рет қаралды 32 М.
Java Program to Check a Number is Prime or Not - In Hindi
10:21
Take Input | Java Foundation Course | Lecture 9
8:18
Pepcoding
Рет қаралды 44 М.
Introduction to Number System
11:58
Pepcoding
Рет қаралды 35 М.
How to Find Duplicates Elements in Java Array? - Java Interview Questions -5
29:34
Man Mocks Wife's Exercise Routine, Faces Embarrassment at Work #shorts
00:32
Fabiosa Best Lifehacks
Рет қаралды 6 МЛН