About 2,840,000 results
Open links in new tab
  1. Recursive program for prime number - GeeksforGeeks

    Jan 27, 2022 · In this article, you will see how you can write the logic of stored procedure to generate prime numbers for any given input. Title : Given a number N print all the prime number (<=N) separated by comma (, ) using Stored Procedure in MYSQL. Example-1 : Input : N = 10 Output : 2, 3, 5, 7 Example-2

  2. Prime Number Using Recursion in Java - PrepInsta

    Here, we will discuss the program for prime number using recursion in Java. We are given with a number and need to check if its prime or not.

  3. Printing prime numbers in Java using recursion - Stack Overflow

    Jul 22, 2014 · Just return whatever the recursive method call returns: return primes(x, i-1); Also, modify the first case's condition to i == 1 so it returns 1 on primes correctly. Works like a charm. The conversion from C to Java was the culprit! At first glance, it appears that you're missing a return in your else statement: if(i==1) return 1; if(x%i==0)

  4. recursion - Java: Find out if a number is prime recursively - Stack ...

    Aug 9, 2017 · I'm writing a function that returns true if a number is prime, and false otherwise. Here is my current code: public static boolean checkPrime(int n, int currDivisor){ if(n < 2){ return true; if(currDivisor == (n/2)){ return true; else if(n % currDivisor == 0 ){ return false; . else{ return checkPrime(n, currDivisor + 1);

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

  6. Check if a number is prime using recursion - Stack Overflow

    Dec 2, 2018 · return isPrimeRecursive(n, i + 2); if (n <= 2 || n % 2 == 0) { return (n == 2); return isPrimeRecursive(n, 3); System.out.println(isPrime(Integer.parseInt(args[0]))); With your code, you should start of i with a value of n-1 since n % n is always true of prime numbers.

  7. Java Program to Check whether a Number is Prime or Not using Recursion

    This is a Java Program to Find if a Number is Prime or Not using Recursion. A number is said to be a prime number if it is divisible only by itself and unity. Enter an integer as an input. Now we create a new method named prime which uses if conditons to give the desired result.

  8. Check Prime Number in Java [3 Methods] - Pencil Programmer

    Method 3: Using Recursion We can also check whether a number is prime or not using a recursive function. To the recursive function, we pass the next potential factor as i and check if it is actually the factor of the number (i.e. n%i == 0 ), if so then we return false otherwise, we increment i and recursively call the function until i=n/2 .

  9. Prime Numbers in Java: Simple Logic and Code - scholarhat.com

    Sep 25, 2024 · 3. Prime Number Program Using Recursion. You can also find the prime numbers in Java using the recursion method. This approach recursively checks for divisibility from 2 up to the square root of the number. Example

  10. Recursive method for prime numbers in JAVA - Stack Overflow

    Dec 6, 2015 · The normal way to handle that using recursion would be to define a recursive "is_divisible" function: # for integers m >= 1 is_prime(m): return is_divisible(m, 1) is_divisible(m, n): if n >= m: return true if n == 1: return is_divisible(m, n + 1) if m % n == 0: return false // HERE return is_divisible(m, n + 1)

  11. Some results have been removed
Refresh