Question: The code snippet below checks whether a given number is a prime number. What will be the result of executing it ? public static void

The code snippet below checks whether a given number is a prime number. What will be the result of executing it?
public static void main(String[] args)
{
int j=2;
int result =0;
int number =0;
Scanner reader = new Scanner(
System.in);
System.out.println("Please enter a number: ");
number = reader nextInt () ;
while number ?2)
{
if (number %j==0)
{
result =1
}
j++;
}
if (result ==1)
{
System.out.println("Number: "+ number +" is Not Prime.");
}
else
{
System, out.println("Number: "+ number +" is Prime. ");
}
}
The code snippet will display the desired result.
The code snippet will loop forever.
The code snippet will display an incorrect result.
The code snippet will not compile.
 The code snippet below checks whether a given number is a

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!