Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started