Write a program in Java to print all the prime number between 1 to 100
public class Prime {
public static void main(String[] args) {
System.out.println("Prime numbers between 1 to 100 :");
int check = 0;
for (int i = 2; i <= 100; i++) {
for (int j = 2; j <= i - 1; j++) {
if (i % j == 0) {
check = 0;
break;
} else {
check = 1;
}
}
if (i == 2) {
System.out.println(i);
}
if (check == 1) {
System.out.println(i);
}
}
}
}
0 Comments:
Post a Comment