Answered step by step
Verified Expert Solution
Question
1 Approved Answer
USING JAVA: - Create a code to calculate the greatest common divisor(GCD) for two positive integers entered by the user. The greatest common divisor of
USING JAVA:
- Create a code to calculate the greatest common divisor(GCD) for two positive integers entered by the user. The greatest common divisor of a number is the largest positive integer that divides each of the integers evenly. For example the GCD of 126 and 12 is 6. (6 x 2 = 12 & 6 x 21 = 126) or the GCD of 4 & 6 is 2. (2 x 2 = 4 & 2 x 3 = 6). These numbers need to be positive as well.
Follow these three steps while coding it:
Part 1 - Get positive number input: For our program to work correctly we need two positive integers. Code your program so that it asks for 2 integers. Then use sentinel while loops to make sure that the input we get is a positive number. Part 2 - Calculate the GCD: Assume our numbers are saved into x&y 1. Subtract x from y repeatedly until y
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