About 3,950,000 results
Open links in new tab
  1. 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.

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

  3. 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 = 11Output: 2, 3, 5, 7, 11Input: N = 7Output: 2, 3, 5, 7 Approach 1: Firstly, consider the given number N as input.Then apply a for loop in order to iterate the numbers from 1 to N.At last, check if ea

  4. Java Program to Print Prime Numbers from 1 to N - Tutorial …

    In this article, we show how to write a Java program to Print Prime Numbers from 1 to N using For Loop, While Loop, and Functions.

  5. Java Program to Print Prime Numbers - W3Schools

    Unlock efficient methods for a prime number program in Java with this tutorial. Learn to check and print prime numbers up to any limit, from 1 to 100. Ideal for boosting your skills in prime number series and generating a list of prime numbers in Java.

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

    Nov 7, 2014 · public void setPrime(int num) j = num; //boolean isPrime() goes here. public boolean isPrime() boolean prime = true; for(int i = 2; i<= j/2; i++) if(j % i >= 0) prime = false; prime = true; return prime; . public String toString() if( isPrime() == false)

  7. Program to print prime numbers from 1 to N. - GeeksforGeeks

    Oct 8, 2024 · Algorithm to print prime numbers: First, take the number N as input. Then use a for loop to iterate the numbers from 1 to N; Then check for each number to be a prime number. If it is a prime number, print it. Approach 1: Print prime numbers using loop.

  8. Prime Numbers using For Loop and While Loop in Java - eStudy

    In this tutorial, we explored how to generate prime numbers using both the for loop and while loop in Java, specifically using the BlueJ programming language. We discussed the syntax, provided examples, and highlighted the differences between these two looping constructs.

  9. Java Program to Check Prime Number - Tutorial Gateway

    Write a Java Program to Check Prime Number using For Loop, While Loop, and Functions. Prime Numbers are any natural number not divisible by any other number except 1 and itself.

  10. Java program to display prime numbers from 1 to 100 and 1 to n

    Sep 10, 2022 · For example 2, 3, 5, 7…are prime numbers. Here we will see two programs: 1) First program will print the prime numbers between 1 and 100 2) Second program takes the value of n (entered by user) and prints the prime numbers between 1 and n.

  11. Some results have been removed
Refresh