Exercise
Prime number
Objetive
Write a java program that asks the user for an integer and determines if it is a prime number or not.
Example Code
import java.util.*;
public class Main
{
public static void main(String[] args)
{
int number;
int dividers = 0;
System.out.print("Enter a number: ");
number = Integer.parseInt(new Scanner(System.in).nextLine());
for (int i = 1; i <= number; i++)
{
if (number % i == 0)
{
dividers++;
}
}
if (dividers == 2)
{
System.out.println("The number is prime");
}
else
{
System.out.println("The number is not prime");
}
}
}