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

    Apr 7, 2025 · A prime number is a natural number greater than 1, divisible only by 1 and itself. Examples include 2, 3, 5, 7, and 11. These numbers have no other factors besides themselves …

  2. Java Program to Display All Prime Numbers from 1 to N

    Jul 2, 2024 · For a given number N, the purpose is to find all the prime numbers from 1 to N. Examples: Input: N = 11 Output: 2, 3, 5, 7, 11 Input: N = 7 Output: 2, 3, 5, 7 . Approach 1: …

  3. java - find all prime numbers from array - Stack Overflow

    May 10, 2015 · System.out.println("Enter the elements of the array: "); for(int i=0; i<5; i++) array[i] = in.nextInt(); //loop through the numbers one by one. for(int i=0; i<array.length; i++){ boolean …

  4. Using For Loop to Get Prime Numbers java - Stack Overflow

    Nov 7, 2014 · Check your condition. A number is prime if it is divisible by only itself and one. change (j%i >= 0) to (j%i == 0) –

  5. java - for loop finding the prime numbers - Stack Overflow

    Jun 4, 2012 · for (long i=2; i<n/2; i++) { if (n%i == 0) { ... Practically in your current version an odd number n will keep dividing by 2 up to n/2 instead of stopping much sooner. Consider n = 21. …

  6. Prime Number Java Program – 1 to 100 & 1 to N | Programs - Java

    Apr 17, 2025 · Find Prime Numbers Between 1 to n. 1) We are finding the prime numbers within the limit. 2) Read the “n” value using scanner object sc.nextInt()and store it in the variable n. 3) …

  7. Generate Prime Numbers with for loop - Java Code Geeks

    Nov 11, 2012 · With this example we are going to demonstrate how to generate prime numbers with a simple for loop. A prime number is a number that has no positive divisors other than 1 …

  8. Java Program to list Prime Numbers using for Loop

    Mar 14, 2021 · This post on Java Program to list Prime numbers using for loop is the same as the Java Program to check whether a number is prime or not.

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

  10. Prime number in java using for loop - tutorialsinhand

    Given below is a java program to check if number is prime number or not. public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Enter …

Refresh