About 2,270,000 results
Open links in new tab
  1. Prime Number Program in Java - GeeksforGeeks

    Apr 7, 2025 · In this article, we will learn how to write a prime number program in Java when the input given is a Positive number. For checking a prime number in Java, there are no formulae available but there are a few methods available to check if a number is Prime or not. There are several methods available to check if a number is prime.

  2. Java Program to Check Whether a Number is Prime or Not

    In this article, you'll learn to check whether a number is prime or not. This is done using a for loop and while loop in Java.

  3. Prime Number Program in Java using Scanner

    Prime Number Program in Java using Scanner. Here, we will use recursion methods to check if a given number is a prime number or not in java. A function/method that contains a call to itself is called the recursive function/method. A technique of defining the recursive function/method is called recursion.

  4. Prime Number Program in Java Using Scanner Example.

    Here is the Java Example for Prime Number Program: import java.util.Scanner; public class PrimeNumber { public static void main(String args[]) { int num,b,c; Scanner s=new Scanner(System.in); System.out.println("Enter A Number"); num =s.nextInt(); b=1; c=0; while(b<= num) { if((num%b)==0) c=c+1; b++; } if(c==2) System.out.println(num +" is a ...

  5. Check for Prime Number - GeeksforGeeks

    Mar 11, 2025 · This method also known as the school method is the simplest way to check if a number n is prime by checking every number from 2 to n-1. If n is less than 2, return false (0 and 1 are not prime). If the number n is divisible by any of these, it's not prime. If …

  6. Java Program to Check if a Number is Prime - Java Guides

    Returns and displays whether the number is prime or not. Output: 5 is a prime number. Output: 10 is not a prime number. Prompt for Input: Use the Scanner class to read an integer input from the user. Check if the Number is Less than 2: Any number less than 2 is not prime.

  7. Prime Number Program in Java | Whether a Number is Prime or Not

    Jan 30, 2025 · This is one of the simplest ways of implementing a program for checking whether a number is a prime number or not in Java. It doesn’t require any input and simply tells whether the defined number (by the integer variable n) is a prime number or not. Here goes the code:

  8. Java Program to Check if a Number is Prime - Master Coding

    A prime number is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers. A simple Java program can check whether a given number is prime through iterative division.

  9. How to check if a number is prime in Java - Educative

    We will use the user-defined isPrime() function in Java, which takes the number as input and returns true if the number is prime and false if it is not. Using for loop Take a number as input.

  10. Java program to check prime number - BeginnersBook

    Sep 10, 2022 · This program takes the number (entered by user) and then checks whether the input number is prime or not. The program then displays the The number which is only divisible by itself and 1 is known as prime number, for example 7 is a prime number because it is only divisible by itself and 1.

  11. Some results have been removed