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");
}
}
```
a. i is 3 followed by 9 is prime
b. i is 3 followed by 9 is not prime
c. i is 4 followed by 9 is prime
d. i is 4 followed by 9 is not prime


d. i is 4 followed by 9 is not prime
isPrime is initialized to true. The loop tests if number is divisble by i for i from 2, 3, and so on. When i is 3, isPrime is false. The loop continuation condition becomes false. The loop is not finished. Before the loop continuation condition is checked, i++ increments i by 1. So, output is that i is 4 and following by 9 is not prime. So, the correct answer is is executed n times for i from 1 to n. So, the correct answer is D.

Computer Science & Information Technology

You might also like to view...

Catch blocks that do not specify an exception type or an identifier ____________.

a) is an error b) cannot catch any exceptions c) can catch any exceptions d) None of the above

Computer Science & Information Technology

High-level languages are used to develop applications, games, Web apps, and most other software.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

Discuss whether the EJB architecture would be suitable to implement a massively multiplayer online game. What would be the strengths and weaknesses of using EJB in this domain?

What will be an ideal response?

Computer Science & Information Technology

Write a Java statement to access the 7 th character in the String variable myString and place it in the char variable c.

What will be an ideal response?

Computer Science & Information Technology