Java Program - Prime Number
Here is the code to find prime numbers between 1 to user defined number. In this program, I am using "for loop" 2 times. First loop start from 1 to user enterned number and another loop divide the number by 2.
class Prime_number {
public static void main(String[] args) {
int num = 11;
int i;
for (i=2; i < num ;i++ ){
int n = num%i;
if (n==0){
System.out.println("is not Prime!");
break;
}
}
if(i == num){
System.out.println("is Prime number!");
}
}
}
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment