WAP in Java to check whether a number is prime or not..
Answers
Answered by
9
Answer:
Refer to the attached picture!☺
Attachments:
Answered by
0
Answer:
public class PRIME_NOT_PRIME {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("ENTER THE NUMBER");
int num=sc.nextInt();
boolean condition=true;
for(int i=2; i<num;i++){
if(num%i==0){
condition=false;
break;
}
}
if(condition && num>=3){
System.out.println(num+" IS A PRIME NO.");
}
else{
System.out.println(num+" IS NOT A PRIME NO.");
}
}
}
Explanation:
Similar questions
Math,
4 months ago
Physics,
9 months ago
English,
9 months ago
Social Sciences,
1 year ago
Math,
1 year ago