About 751,000 results
Open links in new tab
  1. java - Use Modulus Operator to Get Prime Numbers - Stack Overflow

    Jul 23, 2013 · How would you modify the below to print out all prime numbers from 1-100? The below has an issue with the number 2 coming back as not prime. The if(i%number == 0) condition is met for the number 2 as 2%2 is returned as 0.

  2. 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. Methods to Write a Prime Number Program in Java. 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 ...

  3. java - modulo algorithm for prime numbers - Stack Overflow

    Dec 30, 2013 · First of all, at your main method, change if(divisibleCount < 2) to if(divisibleCount <= 2) because primes are divided by 1 and themselves (so, "divisibleCount" is 2). Also, in your while loop, you should check if i equals one and say that it is not a prime. Check your syntax.

  4. Modulo or Remainder Operator in Java - GeeksforGeeks

    Feb 23, 2022 · Modulo or Remainder Operator returns the remainder of the two numbers after division. If you are provided with two numbers, say A and B, A is the dividend and B is the divisor, A mod B is there a remainder of the division of A and B. Modulo operator is an arithmetical operator which is denoted by %.

  5. 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.

    Missing:

    • Modulo

    Must include:

  6. Prime Number Program in Java - Sanfoundry

    Write a Java program to check if a given number is a Prime number. If the number is Prime, then display it is a prime number else display it is not a prime number. What is Prime Number in Java? A prime number is a natural number that is greater than 1 and is only divisible by 1 and itself.

  7. Java Prime Number Method - The Developer Blog

    Modulo: This operation returns 0 if a number is evenly divisible. We thus can use it to detect a possible prime factor. Main: We test some ranges of numbers for primes. We print the first primes—the primes 2, 3, 5, 7, are well-known.

  8. Java Program to Find Prime Numbers in a Given Range

    This is a Java Program to Find Prime Numbers Within a Range of n1 and n2. Enter the upper and lower limits as input. Now we use modulus operation along with double for loops and if-else conditions to get the output. Here is the source code of the Java Program to Find Prime Numbers Within a Range of n1 and n2.

  9. How To Use Modulo, Modulus, Or Remainder Operator In Java?

    Aug 17, 2022 · We can easily determine if a number is divisible by any other number or not using the mod operator. The Java code for checking a prime number is demonstrated below: 1. public class Main { 2. public static void main(String[] args) { 3. int number = 17; 4. boolean flag = false; 5. for (int i = 2; i <= number / 2; ++i) { 6. if (number % i == 0 ...

  10. Check for Primeness of a Number in Java - usingMaths.com

    A fast Check for Primeness in Java. So for our quick check, we will use the range of 2 to &Sqrt;number. Type out the adjoining Java code for fast check for primeness. Note: You can simply tweak the existing function.

  11. Some results have been removed
Refresh