Java Program To Check Prime Numbers | Print Prime Numbers | Java Practice Problems | Code Bode

preview_player
Показать описание
#primenumbers | #javatutorails | #javapracticeproblems

Hi guys,
In this video, we will learn how to check if a number is prime or not.
Let's understand what is a prime number and non-prime number
prime number - a number only divisible by 1 and itself
non-prime number - if divisible by any other number apart from 1 and itself

Algorithm/Logic
// 1. input number from the user
// 2. check divisiblity by other numbers - iterate a for loop - 2 to input/2
// 3. condition to check divisiblity using %
// 4. set a flag as false
// 5. if it is divisible print not prime; break the loop; and set flag to true
// 6. after loop completes check if flag is still false. if flag is fase print prime

Stay tuned for more practice problems

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

no need for the flag. totally useless. remove all the flags and it will work as well

mohammadaliizadifar
welcome to shbcf.ru