Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Information Quality Dimensions, Principles And Techniques

Authors: Carlo Batini, Monica Scannapieco

1st Edition

3319241060, 9783319241067

More Books

Students also viewed these Databases questions

Question

Question Can I collect benefits if I become disabled?

Answered: 1 week ago

Question

Question May I set up a Keogh plan in addition to an IRA?

Answered: 1 week ago