Java Program to check whether number is Palindrome or not | Java Find Palindrome Number
Java program to check if a number is Armstrong : Find Armstrong Number In Java
Java program to remove duplicate elements from an array
Java program to check if string is a palindrome : check palindrome string in java
What is OSI Model In Hindi | Layers of OSI model
Password Strength Checker In jQuery In Hindi
JavaScript eval() Function In Hindi | JS eval() Function
If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
Image on pixabay
Prime Numbers मतलब अभाज्य संख्याएँ वे पूर्ण संख्याएँ (whole numbers) हैं जिनके स्वयं और 1 के अलावा और कोई भी गुणनखण्ड नहीं होते हैं। या कह सकते हैं कि जिन्हे 1 या खुद के number के अलावा किसी से विभाजित नहीं किया जा सकता है।
जैसे: 2,3,5,7,11 इत्यादि , इनमे अगर आप 1 और उस सख्या अलावा किसी भी और number से भाग नहीं कर सकते हैं।
इस article में Java language में हम Prime number check करने के लिए एक program बनाएंगे।
// import package.
import java.util.*;
public class PrimeExample {
// define static function to check prime number.
static boolean isPrime(int n) {
if (n <= 1) {
return false;
}
for (int i = 2; i < n; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
// main method
public static void main(String[] args) {
// get input from user
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number: ");
int num = sc.nextInt();
// call the function
boolean check = isPrime(num);
if (check) {
System.out.println(num + " is a prime number.");
} else {
System.out.println(num + " is not a prime number.");
}
}
}
Output :
Enter a number: 12 12 is not a prime number. Enter a number: 19 19 is a prime number.
Note* : program में Scanner class का use किया गया है , ताकि user से input ले सकें।
Loading ...
Hi ! My name is Rahul Kumar Rajput. I'm a back end web developer and founder of learnhindituts.com. I live in Uttar Pradesh (UP), India and I love to talk about programming as well as writing technical tutorials and tips that can help to others.
Get connected with me. :) LinkedIn Twitter Instagram Facebook