Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Step: 3

blur-text-image

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

More Books

Students also viewed these Databases questions

Question

What are the advantages of the subsidiary organization form?

Answered: 1 week ago

Question

If striving to meet schedule or budget isnt top priority, what is?

Answered: 1 week ago

Question

Introduction to vectors r studio challenge

Answered: 1 week ago

Question

understand the key issues concerning international assignments

Answered: 1 week ago