0% found this document useful (0 votes)
9 views2 pages

Java 3

The document contains a Java program that prints prime numbers up to a user-defined limit. It utilizes a method to check if a number is prime and iterates through numbers starting from 2 to the specified limit. The output displays all prime numbers found within that range.

Uploaded by

121pratham2032
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Java 3

The document contains a Java program that prints prime numbers up to a user-defined limit. It utilizes a method to check if a number is prime and iterates through numbers starting from 2 to the specified limit. The output displays all prime numbers found within that range.

Uploaded by

121pratham2032
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

3. Write a program to print prime number series.

import java.u l.Scanner;

public class PrimeNumberSeries {

public sta c void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.print("Enter the limit: ");

int limit = scanner.nextInt();

System.out.println("Prime numbers up to " + limit + " are:");

for (int i = 2; i <= limit; i++) {

if (isPrime(i)) {

System.out.print(i + " ");

scanner.close();

public sta c boolean isPrime(int number) {

if (number <= 1) {

return false;

for (int i = 2; i <= Math.sqrt(number); i++) {

if (number % i == 0) {

return false;

return true;

}
O/P: Enter the limit: 50

Prime numbers up to 50 are:

2 3 5 7 11 13 17 19 23 29 31 37 41 43 47

You might also like