JAVA to write the code. : Euclid’s algorithm for finding the greatest common divisor (gdc) of two numbers The algorithm: given two numbers, n1 and n2: Divide n1 by n2 and let r be the remainder. If the remainder r is 0, the algorithm is finished and the answer is n2. (If the remainder is 1, the numbers are mutually prime and we are done-see below.) Set n1 to the value of n2, set n2 to the value of r, and go back to step 1. Entering 0 for one of the values is bad.  It should work for the other value, but you have to figure out which is OK and which is bad. Catch this problem as it happens and make the user enter another value until they enter an acceptable one. Give an appropriate error message if this happens.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter8: Arrays And Strings
Section: Chapter Questions
Problem 21PE
icon
Related questions
Question

use JAVA to write the code.

: Euclid’s algorithm for finding the greatest common divisor (gdc) of two numbers

The algorithm: given two numbers, n1 and n2:

  1. Divide n1 by n2 and let r be the remainder.
  2. If the remainder r is 0, the algorithm is finished and the answer is n2. (If the remainder is 1, the numbers are mutually prime and we are done-see below.)
  3. Set n1 to the value of n2, set n2 to the value of r, and go back to step 1.
  • Entering 0 for one of the values is bad.  It should work for the other value, but you have to figure out which is OK and which is bad.
    • Catch this problem as it happens and make the user enter another value until they enter an acceptable one.
    • Give an appropriate error message if this happens.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Time complexity
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr