About 1,510,000 results
Open links in new tab
  1. java - find all prime numbers from array - Stack Overflow

    May 10, 2015 · This is the simplest form of finding the prime numbers from the given array. We can also use scanner by assigning n instead of an array to check whether if it is a prime or non prime from the given input(commented in program).Hope this helps you..!!

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

  3. Java program to print prime numbers from an array - Medium

    Jan 4, 2017 · To print the prime numbers from an array, user has to declare the size of the array size and enter the elements of the array. Prime numbers are identified using iterations with the help...

  4. Count number of primes in an array - GeeksforGeeks

    Sep 1, 2022 · Given an array arr[] of N positive integers. The task is to write a program to count the number of prime elements in the given array. Examples: Input: arr[] = {1, 3, 4, 5, 7} Output: 3 There are three primes, 3, 5 and 7 Input: arr[] = {1, 2, 3, 4, 5, 6, 7} Output: 4

  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.

  6. How can I find all prime numbers from array in Java

    Feb 22, 2022 · I want to find all prime numbers from array and print them in main class. public List<Integer> getListOfPrimes(int[] source) { List<Integer> result = new ArrayList<>(); for (int i = 0; i < source.length; i++) { if (primeCheck(source[i] == true) result.add(); return result; private boolean primeCheck(int value) { if (value < 2) return false;

  7. Java Program to find prime numbers in an array - Xiith

    In this program, You will learn how to find prime numbers in an array in java. public static void main(String[] args) { //Statement. Example: How to find prime numbers in an array in java. s = sc.nextInt(); System.out.print("Enter array elements:"); for (i = 0; i < s; i++) { .

  8. java - Prime numbers in array - Stack Overflow

    Jan 20, 2014 · ArrayList primeNumbers = new ArrayList(); for (int i = 0; i <= number; i++) if(isPrime(i)) . primeNumbers.add(i); return primeNumbers; for(int i=2;i<n;i++) . if(n%i==0) return false; return true; can you do it without the ArrayList?

  9. Write a program to Find prime and non-prime numbers in the array

    The code checks whether each element in the given array a is prime or not. It uses a nested loop to iterate over each element and then over all the numbers from 2 to half of the element's value. If any number divides the element, it is not prime, and …

  10. Java 8 Program To Find Prime Number - Java Guides

    This Java 8 program efficiently checks if a number is prime using streams. By leveraging Java 8's IntStream and noneMatch() methods, the program provides a concise and efficient way to determine the primality of a number.

Refresh