JAVA CODES for prime no between 1 and given no

import java.util.Scanner;

public class Prime_No_Between_1_and_given_no {
public static void main(String[] args) {
int count;
Scanner sc = new Scanner(System.in);
System.out.println("enter the number");
int no = sc.nextInt();
System.out.println("The prime number between 2 and "+no+ " are");
for (int i = 2; i < no; i++) {
count = 0;
for (int j = 2; j < i; j++) {
if (i % j == 0) {
count++;
}
}
if (count == 0) {
System.out.println( i);
}
}
}
}

No comments:

Post a Comment