Answered step by step
Verified Expert Solution
Link Copied!

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:

image text in transcribed

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=x : y=x int temp =y y=x x= temp print(y) Part 3 - Loop the program: Lastly, lets have the program loop when the user enters in " y " or "Y

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

Advances In Spatial And Temporal Databases 11th International Symposium Sstd 2009 Aalborg Denmark July 8 10 2009 Proceedings Lncs 5644

Authors: Nikos Mamoulis ,Thomas Seidl ,Kristian Torp ,Ira Assent

2009th Edition

3642029817, 978-3642029813

More Books

Students also viewed these Databases questions

Question

Name and describe two anxiety disorders.

Answered: 1 week ago

Question

What are the determinants of cash cycle ? Explain

Answered: 1 week ago