Question: The program prompts the user to input an integer. Try to find a divisor for this integer, if there are no divisors the integer is

The program prompts the user to input an integer. Try to find a divisor for this integer, if there are no divisors the integer is a prime number, otherwise it is not a prime number.

*/

import java.util.Scanner;

public class Lab5Part3 {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

int num;

int divisor;

System.out.println("Enter an integer greater than 1");

num = input.nextInt();

divisor = num / 2;

while (num % divisor != 0) {

System.out.println("Trying factor " + divisor);

divisor--;

}

if (divisor == 1) {

System.out.print("The input integer " + num + " is a prime

number");

} else {

System.out.print("The input integer " + num + " is divisible

by " + divisor);

}

}

/* Answer the following questions about this code:

* 1. What is the loop control variable?

* 2. What statement initializes the loop control variable?

* 3. What is the loop condition?

* 4. What statement updates the loop control variable?

*

* After you answer above questions, comment out the main method

given and

write your own main method. In your main method use a "for" loop

instead of the while loop.

*/

}

/*

* Copy and paste your program output here

*/

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!