# Java program to display prime numbers from 1 to 100

Let’s learn java program to display prime numbers from 1 to 100.

## Java program to display prime numbers from 1 to 100

A prime number is one which is divisible by 1 and itself.

Here’s the program to display prime numbers from 1 to 100.

```public class PrimeNumbersFrom1To100
{
public static void main(String[] args)
{
int maxNumber = 100;
boolean prime = true;
for(int a = 1; a <= maxNumber; a++)
{
prime = checkPrime(a);
if(prime)
{
}
}
System.out.println("Display prime numbers from 1 to " + maxNumber + ": ");
}
public static boolean checkPrime(int number)
{
int remainder;
for(int a = 2; a <= number / 2; a++)
{
remainder = number % a;
// if remainder is equal to 0 then number is not prime
if(remainder == 0)
{
return false;
}
}
return true;
}
}
```

Output:

Display prime numbers from 1 to 100:
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

Java program to display prime numbers from 1 to n

Similarly we can display prime numbers from 1 to n.

```import java.util.Scanner;
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int a = 0;
int number = 0;
System.out.println("Please enter the value of n : ");
int n = sc.nextInt();
for(a = 1; a <= n; a++)
{
int count = 0;
for(number = a; number >= 1; number--)
{
if(a % number == 0)
{
count = count + 1;
}
}
if(count == 2)
{
}
}
System.out.println("Java program to display prime numbers from 1 to n : ");