public class PrimeNumber1To100 {
public static void main(String[] args) {
System.out.println("Prime numbers from 1 to 100 are :");
for(int i=1;i<=100;i++) {
int counter=0;
for(int num = i;num>=1;num--) {
if(i%num == 0) {
counter++;
}
}
if(counter == 2) {
System.out.print(i+" ");
}
}
}
}
Output:-
Prime numbers from 1 to 100 are :
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
Thursday, August 5, 2021
How to find prime numbers from 1 to 100
Subscribe to:
Post Comments (Atom)
How to sort an HashMap based on value
import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.LinkedHashMap; import java....
-
http://www.roseindia.net/apachevelocity/velocity-tutorials.shtml
-
http://download.oracle.com/javase/tutorial/uiswing/start/index.html
-
function data_change(field) { var check = true; var value = field.value; //get characters //check that all ch...
No comments:
Post a Comment