---
description: Print Prime Number From 1 to 100 in Java - Here is a Java program to print prime numbers from 1 to 100 (1 to N) with program logic and example.
title: Program to Print Prime Number From 1 to 100 in Java
---

 

[Skip to content](#main) 

## What is a Prime Number?

A **Prime Number** is a number that is only divisible by one or itself. It is a natural number greater than one that is not a product of two smaller natural numbers. For example, 11 is only divisible by one or itself. Other Prime numbers 2, 3, 5, 7, 11, 13, 17, etc.

**Note:** 0 and 1 are not prime numbers. 2 is the only even prime number.

## How to Print Prime Numbers Between 1 to 100 Program in Java

Below is the Java program to print prime numbers from 1 to 100:

**Program Logic:**

* The main method of [prime number program in Java](https://www.guru99.com/java-program-check-prime-number.html) contains a loop to check prime numbers between 1 to 100 in Java one by one.
* The main method calls the method `CheckPrime` to determine whether a number is prime number in Java or not.
* We need to divide an input number, say 17 from values 2 to 17 and check the remainder. If the remainder is 0 number is not prime.
* No number is divisible by more than half of itself. So, we need to loop through just numberToCheck/2\. If the input is 17, half is 8.5, and the loop will iterate through values 2 to 8
* If `numberToCheck` is entirely divisible by another number, we return false, and loop is broken.
* If `numberToCheck` is prime, we return true.
* In the main method for prime numbers 1 to 100 in Java, check isPrime is `TRUE` and add to primeNumbersFound String
* Lastly, print prime numbers from 1 to 100 in Java

public class primeNumbersFoundber {

    public static void main(String[] args) {

        int i;
        int num = 0;
        int maxCheck = 100; // maxCheck limit till which you want to find prime numbers
        boolean isPrime = true;

        //Empty String
        String primeNumbersFound = "";

        //Start loop 2 to maxCheck
        for (i = 2; i <= maxCheck; i++) {
            isPrime = CheckPrime(i);
            if (isPrime) {
                primeNumbersFound = primeNumbersFound + i + " ";
            }
        }
        System.out.println("Prime numbers from 1 to " + maxCheck + " are:");
        // Print prime numbers from 1 to maxCheck
        System.out.println(primeNumbersFound);
    }
    public static boolean CheckPrime(int numberToCheck) {
        int remainder;
        for (int i = 2; i <= numberToCheck / 2; i++) {
            remainder = numberToCheck % i;
            //if remainder is 0 than numberToCheckber is not prime and break loop. Else continue loop
            if (remainder == 0) {
                return false;
            }
        }
        return true;

    }

}

## Expected Output:

The output of the prime number between 1 to 100 in [Java program](https://www.guru99.com/java-tutorial.html) will be:

Prime numbers from 1 to 100 are:
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97

Check our program to Find [Prime Numbers from Any Input Number](https://www.guru99.com/java-program-check-prime-number.html) 

This code is editable. Click Run to Compile + Execute   

![](https://www.guru99.com/Customization/CodeEditorFiles/Common/ajax-loader.gif)

#### Summarize this post with:

ChatGPT Perplexity Grok Google AI 

**Stay Updated on AI** **Get Weekly AI Skills, Trends, Actionable Advice.** 

##### Sign up for the newsletter

Subscribe for Free 

You have successfully subscribed.  
Please check your inbox. 

![AI-Newsletter](https://www.guru99.com/images/footer-email-avatar-imges-1.png) Chosen by over **350,000+** professionals 

[Scroll to top ](#wrapper)Scroll to top 

× 

Toggle Menu Close 

Search for: 

Search

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://www.guru99.com/#organization","name":"Guru99","sameAs":["https://www.facebook.com/Guru99Official","https://twitter.com/guru99com"],"logo":{"@type":"ImageObject","@id":"https://www.guru99.com/#logo","url":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","contentUrl":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","caption":"Guru99","inLanguage":"en-US"}},{"@type":"WebSite","@id":"https://www.guru99.com/#website","url":"https://www.guru99.com","name":"Guru99","publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US"},{"@type":"BreadcrumbList","@id":"https://www.guru99.com/prime-number-program-java.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":"1","item":{"@id":"https://www.guru99.com","name":"Home"}},{"@type":"ListItem","position":"2","item":{"@id":"https://www.guru99.com/java-tutorials","name":"Java Tutorials"}},{"@type":"ListItem","position":"3","item":{"@id":"https://www.guru99.com/prime-number-program-java.html","name":"Program to Print Prime Number From 1 to 100 in Java"}}]},{"@type":"WebPage","@id":"https://www.guru99.com/prime-number-program-java.html#webpage","url":"https://www.guru99.com/prime-number-program-java.html","name":"Program to Print Prime Number From 1 to 100 in Java","dateModified":"2024-03-09T15:00:01+05:30","isPartOf":{"@id":"https://www.guru99.com/#website"},"inLanguage":"en-US","breadcrumb":{"@id":"https://www.guru99.com/prime-number-program-java.html#breadcrumb"}},{"@type":"Person","@id":"https://www.guru99.com/author/james","name":"James Hartman","description":"I am James Hartman, a seasoned professional in Oracle Certified Java Professional tutorials, specializing in crafting comprehensive guides to help you excel in your Java certification journey.","url":"https://www.guru99.com/author/james","image":{"@type":"ImageObject","@id":"https://www.guru99.com/images/james-hartman-author-v2-120x120.png","url":"https://www.guru99.com/images/james-hartman-author-v2-120x120.png","caption":"James Hartman","inLanguage":"en-US"},"worksFor":{"@id":"https://www.guru99.com/#organization"}},{"@type":"NewsArticle","headline":"Program to Print Prime Number From 1 to 100 in Java","keywords":"java","dateModified":"2024-03-09T15:00:01+05:30","articleSection":"Java Tutorials","author":{"@id":"https://www.guru99.com/author/james","name":"James Hartman"},"publisher":{"@id":"https://www.guru99.com/#organization"},"description":"Print Prime Number From 1 to 100 in Java - Here is a Java program to print prime numbers from 1 to 100 (1 to N) with program logic and example.","copyrightYear":"2024","copyrightHolder":{"@id":"https://www.guru99.com/#organization"},"name":"Program to Print Prime Number From 1 to 100 in Java","@id":"https://www.guru99.com/prime-number-program-java.html#richSnippet","isPartOf":{"@id":"https://www.guru99.com/prime-number-program-java.html#webpage"},"inLanguage":"en-US","mainEntityOfPage":{"@id":"https://www.guru99.com/prime-number-program-java.html#webpage"}}]}
```
