Question: Suppose the input for number is 9 . What is the output from running the following program? import java.util.Scanner; public class Test { public static

Suppose the input for number is 9. What is the output from running the following program?
import java.util.Scanner;
public class Test {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.print("Enter an integer: ");
int number = input.nextInt();
int i;
boolean isPrime = true;
for (i =2; i < number && isPrime; i++){
if (number % i ==0){
isPrime = false;
}
}
System.out.println("i is "+ i);
if (isPrime)
System.out.println(number +" is prime");
else
System.out.println(number +" is not prime");
}
}
i is 3 followed by 9 is prime
i is 4 followed by 9 is prime
i is 4 followed by 9 is not prime
i is 3 followed by 9 is not prime

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!