a. prime or not
Prime number: A prime number is a whole number greater than 1 whose only factors are 1 and itself.
Ans:
---
public class PrimeTest {
public static void main(String[] args) {
int n, i, k=0;
System.out.println("Enter a positive integer: ");
Scanner sc = new Scanner(System.in);
n=sc.nextInt();
for(i=2;i<=n/2;++i){
if(n%i==0){
k=1;
break;
}
}
if (k==0)
System.out.println(n+" is a prime number");
else {
System.out.println(n+" is not a prime number");
}
sc.close();
}
}
Output:
-------
Enter a positive integer: 29
29 is a prime number.
Prime number: A prime number is a whole number greater than 1 whose only factors are 1 and itself.
Ans:
---
public class PrimeTest {
public static void main(String[] args) {
int n, i, k=0;
System.out.println("Enter a positive integer: ");
Scanner sc = new Scanner(System.in);
n=sc.nextInt();
for(i=2;i<=n/2;++i){
if(n%i==0){
k=1;
break;
}
}
if (k==0)
System.out.println(n+" is a prime number");
else {
System.out.println(n+" is not a prime number");
}
sc.close();
}
}
Output:
-------
Enter a positive integer: 29
29 is a prime number.
0 comments:
Post a Comment