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

Java Program 1-Prime Number

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

Java Program 1-Prime Number

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

import [Link].

Scanner;
public class PrimeNumbersUpToN {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter an integer: ");
int n = [Link]();
[Link]("Prime numbers up to " + n + ":");
for (int i = 2; i <= n; i++) {
if (isPrime(i)) {
[Link](i + " ");
}
}
[Link]();
}
// Method to check if a number is prime
public static boolean isPrime(int num) {
if (num < 2) return false;
for (int i = 2; i <= [Link](num); i++) {
if (num % i == 0) {
return false;
}
}
return true;
}
}
Output:
Enter an integer: 10
Prime numbers up to 10:
2357

Prime Numbers 1 to 100

List of Numbers Prime Numbers

Between 1 and 10 2, 3, 5, 7

Between 11 and 20 11, 13, 17, 19

Between 21 and 30 23, 29

Between 31 and 40 31, 37

Between 41 and 50 41, 43, 47

53, 59, 61, 67, 71, 73, 79, 83, 89,


Between 51 and 100 97

You might also like