Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a program that asks the user for two positive integers. If the user's input for either integer is not positive (less than or equal

Create a program that asks the user for two positive integers. If the user's input for either integer is not positive (less than or equal to 0), re-prompt the user until a positive integer is input. You may assume that all inputs will be integers.

Print out a list, ascending from 1, of all divisors common to both integers. Then, print out a message stating whether or not the numbers are "relatively prime" numbers. Two positive integers are considered relatively prime if, and only if, the only common divisor they have is 1.

For example, if the user inputs 8 and 12 the output should be:

Common divisors of 8 and 12:

1

2

4

8 and 12 are not relatively prime.

If the user inputs 8 and 9, on the other hand, the output should be:

Common divisors of 8 and 9:

1

8 and 9 are relatively prime.

Starter Code:-

import java.util.Scanner;

public class RelativelyPrime { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); //Scanner to get user input //TODO //Complete the program } }

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

Oracle Database 19c DBA By Examples Installation And Administration

Authors: Ravinder Gupta

1st Edition

B09FC7TQJ6, 979-8469226970

More Books

Students also viewed these Databases questions