Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Java Coding- Euclid's Algorithm Euclid's algorithm computes the greatest common divisor of two input positive integers. The greatest common divisor is the largest positive integer

Java Coding- Euclid's Algorithm

Euclid's algorithm computes the greatest common divisor of two input positive integers. The greatest common divisor is the largest positive integer that divides evenly into both of the input values.

The algorithm uses the Definition of Division, which states that for any two integers a and b, there exist integers q and r such that a = q ( b ) + r. In this representation, q is the quotient and r is the remainder.

Given two positive integers a and b, the algorithm proceeds as follows:

  1. For the given values of a and b, apply the Definition of Division and compute the quotient q and remainder r;
  2. If r > 0, then update a and by by assigning the value of b to a and also assigning the value of r to b, and then repeat Step 1 with the updated values.
  3. If r = 0, then the greatest common divisor of the original a and b is the last computed non-zero value for r.

  1. Create a Java project in Eclipse called "Euclid"
  2. Create the class "Euclid" in the "src" subfolder of the package (Eclipse will put this class in the file Euclid.java)
  3. Run your Java code in Eclipse using a run configuration that passes 2 sample inputs
  4. Open a command window and navigate to your desktop
  5. Test your JAR by running it with some sample input values, for example: "java -jar Euclid.jar 5763 187"
  6. Verify that your JAR contains your Java source file by using the "jar tvf " command

***REQUIRED OUTPUT***

The main method should output the following as the output header:

  • an empty line
  • a line of just hyphens (dashes)
  • another empty line
  • the words "Euclid's Algorithm by " followed by your name (or names, if teaming
  • another empty line
  • the word "Inputs: " followed by the two input values in the order they were input, separated by a comma
  • another empty line

image text in transcribed

Euclid's Algorithm by : Inputs: 5763, 187 5763 = 30 ( 187 ) + 153 187 = 1 ( 153 ) + 34 153-4 34) + 17 34=2(17 ) +0 -> gcd( 5763, 18717

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions