Write a program to find whether a given number is prime or not.
Answer / Rahul Mishra
In Java, here's a simple program that checks if a number is prime:
```
import java.util.Scanner;
public class PrimeChecker {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number to check for primality:");
int num = sc.nextInt();
if (num <= 1) {
System.out.println(num + " is not prime.");
} else {
for (int i = 2; i < num; i++) {
if (num % i == 0) {
System.out.println(num + " is not prime.");
return;
}
}
System.out.println(num + " is prime.");
}
}
}
```
| Is This Answer Correct ? | 0 Yes | 0 No |
what is runtime exception and compiletime exception ?
DIFFERENCE BETWEEN BINDING LANG AND BIND DIR WHEN USING IN SERVICE PGM
What is the merger sort principle and its time complexity.
What is the Difference between in memory database and physical database
Can anyone provide as400 training material or any institute in bangalore for as400 training
There are 3 jars containing two types of round marbles. One jar contains only red marbles, one jar contains only blue marbles and the third jar contains a mix of both red and blue marbles. Although the jars are labeled “red”, “blue” and “mixed” – all the jars are mislabeled. How many marbles would you have to pull out, and out of which jars, to find out how to fix the labels correctly?
what is the pl/sql block size in oracle 10g and 11g?
what is the abap/4
what is the current salary package in India for a lamp programmer
iam confused among testing ,.net and java. can anybody help me.
Hi guys... I have one doubt ..Exception is a runtime error then why we have checked exception... Thanks in advance
What Is The Difeerence Between C & C++