Home / Expert Answers / Computer Science / nbsp-nbsp-suppose-the-input-for-number-is-9-what-is-the-output-from-running-the-following-pa729

(Solved):     Suppose the input for number is 9. What is the output from running the following ...



Suppose the input for number is 9. What is the output from running the following program?
import java.util.Scanner;
public cl

 

system.out.print(Enter an integer: ); int number = input.nextlnt();
int \( \mathrm{i} \);
boolean isPrime \( = \) true;
for

 

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.nextlnt(); int \( \mathrm{i} \); boolean isPrime \( = \) true; for \( (i=2 ; i< \) number \( \& \& \) isPrime; \( i++)\} \) if (number \% i == 0) \{ isPrime \( = \) false; ] System.out.println("i is " \( +\mathrm{i}) \); if (isPrime) System.out.printin(number + "is prime"); else system.out.print("Enter an integer: "); int number = input.nextlnt(); int \( \mathrm{i} \); boolean isPrime \( = \) true; for \( (i=2 ; i< \) number \& \& isPrime; \( i++)\{ \) if (number \% \( i==0 \) ) \{ isPrime \( = \) false; \} \} System.out.println("i is " \( +\mathrm{i}) \); if (isPrime) System.out.println(number + "is prime"); else System.out.println(number + "is not prime");


We have an Answer from Expert

View Expert Answer

Expert Answer


The given program is used to find if the input number is prime or not. To determine if the number is prime or not, we simply loop from 2 till the inpu
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe