Тёмный

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

Pepcoding
Подписаться 197 тыс.
Просмотров 106 тыс.
50% 1

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 - nados.io/conte...
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 - nados.io/conte...
We are also available on the following social media platforms: -
Facebook(Meta) - / pepcoding
Instagram - / pepcoding
LinkedIn - / pepc. .
Pinterest - / _c. .
Twitter - / pepcoding
RU-vid (English Channel)- / @pepcodingprogrammingi...
Also take a look at our placement assistance - www.pepcoding....
HAPPY PROGRAMMING!
Pep it up.....
Hashtags
#java #javafoundation #isnumberaprime

Опубликовано:

 

7 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 98   
@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❤❤🙏🙏.
@shubhamaggarwal3823
@shubhamaggarwal3823 4 года назад
i loved the way u solved the question in pieces ....😍😍
@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.
@travel2react567
@travel2react567 3 года назад
Best problem solving approach. aise to aaj tak kisi ne programming nahi samjhaya.
@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
@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 👍
@MadaraUchiha1706_
@MadaraUchiha1706_ День назад
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...
@manikasunal7687
@manikasunal7687 3 года назад
You are one of the best teacher 🙌
@Pepcoding
@Pepcoding 3 года назад
Wow, thank you!
@Farhan-uo2ll
@Farhan-uo2ll 6 дней назад
❤️❤️thnku so much sir
@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
@snehasomnathe8802
@snehasomnathe8802 Год назад
Best Explanation, I have ever seen
@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"); } } } }
@yubarajmohanty70
@yubarajmohanty70 Месяц назад
thank you sir
@himanshuaggarwal2445
@himanshuaggarwal2445 3 года назад
sir you teach best i loved it 👍
@Pepcoding
@Pepcoding 3 года назад
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
@ojasgupta1189
@ojasgupta1189 2 года назад
Great sir !!!!
@SCRIPTSAG
@SCRIPTSAG 4 года назад
Sir es tarike se socha nhi kabhi pahli bar lag rha hai ki coding hoti kya hai
@th3graduate292
@th3graduate292 Месяц назад
it took time but i understood it very well.
@techeduidea2598
@techeduidea2598 2 года назад
Sir kuch set of question ka practice kara dijiye Time and Space Complexity par please
@pratikdeore7427
@pratikdeore7427 Год назад
Very helpful explanation :)
@poojachoudhary4607
@poojachoudhary4607 12 дней назад
How you get to know that T will do operations of 10 to the power 4 exactly ?
@nustagame25
@nustagame25 11 дней назад
Problem statement
@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)
@rock_213
@rock_213 2 года назад
Thank you so much sir❤
@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.
@yashgarg3373
@yashgarg3373 3 года назад
I Learned a new way to solve it... thank you sir..
@Pepcoding
@Pepcoding 3 года назад
Most welcome
@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?
@mr.nobody8365
@mr.nobody8365 2 года назад
*Completed*
@RobbyDongre
@RobbyDongre 3 года назад
Sir suppose if we are checking for number "1" . Answer prime ayga is approach see . Any solution for that ?
@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 3 года назад
you are right. but I think you don't see the constraints in the question that is (2
@shubhamaggarwal3823
@shubhamaggarwal3823 4 года назад
thank you sir 🙏🙏👍👍
@nightcrusader5047
@nightcrusader5047 3 года назад
Damn good explanation sir
@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 )
@RohitGupta-kl7je
@RohitGupta-kl7je 3 года назад
I run the same program it's saying for n .. Variable declaration is not allowed here
@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 !!
@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.
@StudyWithAnupam
@StudyWithAnupam 2 года назад
What is the use of Int Count ?
@simarjeetsingh6531
@simarjeetsingh6531 3 дня назад
+1
@prathamdhiman764
@prathamdhiman764 3 года назад
Sir u didn't told us earlier about count and div
@shivamsetia4711
@shivamsetia4711 Год назад
Can anyone explain how this code is working for number 15
@bentennyson8923
@bentennyson8923 3 года назад
sir, please correct the test cases for this question.
@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
@gokul6120
@gokul6120 4 года назад
Sir aap count kyo use kiye.
@Pepcoding
@Pepcoding 4 года назад
bhot sare tareeke hain. ye bhi to theik hai.
@vedanthbaliga7686
@vedanthbaliga7686 4 года назад
Is this the sieve of eratosthenes algorithm?
@Pepcoding
@Pepcoding 4 года назад
Nope. But this is also optimizes somewhat.
@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.
@adityarenapure7397
@adityarenapure7397 4 года назад
sir where is our academy??
@Pepcoding
@Pepcoding 4 года назад
pitampura, delhi
@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
@Japanpreet
@Japanpreet 2 года назад
I didn't get it
@NoOne-jl2ii
@NoOne-jl2ii Год назад
12 / 554
@bhanupratapsingh5468
@bhanupratapsingh5468 4 года назад
Sumit Sir do you teach Python also?
@Pepcoding
@Pepcoding 4 года назад
Not now but we will cover it soon.
@KishanYadav-fn1gl
@KishanYadav-fn1gl Год назад
(√n) root nka concept nhi samja koi explain kar do
@waseemqureshi3607
@waseemqureshi3607 Год назад
sir isme t kya krr rha hai
@geetanegi2736
@geetanegi2736 3 года назад
Sir level 1 ka lia notes bnana jruri hai kya???????🇮🇳🔥😎🇮🇳
@Pepcoding
@Pepcoding 3 года назад
nhi to
@deepakgauttam29
@deepakgauttam29 2 года назад
Sir n=1 per work nhi kar rha
@stayuptodate6441
@stayuptodate6441 Год назад
just modify the condition as if (count == 0 && n!=1)
@lakshmipunugula2274
@lakshmipunugula2274 2 года назад
sir,can you please explain in english.
@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.
@thiyageshkanna
@thiyageshkanna 3 года назад
Would be better if you teach in english!!!
Далее
Bike Challenge
00:20
Просмотров 20 млн
Самое неинтересное видео
00:32
Java Program #6 -  Find Prime Numbers in Java
8:49
Просмотров 9 тыс.
Pattern-1 | Solution | Java Foundation Course
15:10
Просмотров 41 тыс.
Any base Addition | Solution
13:11
Просмотров 30 тыс.
Pattern-13 | Solution | Java Foundation Course
11:26
Просмотров 31 тыс.
Introduction to Number System
11:58
Просмотров 34 тыс.
basics of CODING in 10 minutes
15:34
Просмотров 1,5 млн
Bike Challenge
00:20
Просмотров 20 млн