Java program to remove duplicate elements from an array
Java program to check if a number is Armstrong : Find Armstrong Number In Java
Java program to check if string is a palindrome : check palindrome string in java
Java Program to check whether number is Palindrome or not | Java Find Palindrome Number
Best Laptops Under 50k On Amazon In 2023
PHP ctype Functions | ctype Functions In PHP In Hindi
Back end developer roadmap : how to became back end developer ? back end development kya hai?
PHP Interview Questions In Hindi : PHP Interview Preparation
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.
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 ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)
Get connected with me. :) LinkedIn Twitter Instagram Facebook