1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
harina [27]
3 years ago
10

First write a method to calculate the greatest common divisor (GCD) of two positive integers using Euclid’s algorithm (also know

n as the Euclidean algorithm). Then write a main method that requests two positive integers from the user, validates the input, calls your method to compute the GCD, and outputs the return value of the method (all user input and output should be done in main). Check Wikipedia to find more information about GCDs1 and Euclid’s algorith
Computers and Technology
1 answer:
MAVERICK [17]3 years ago
7 0

Answer:

import java.util.Scanner;

public class Gcd

{

public static void main(String[] args) {

 Scanner input = new Scanner(System.in);

 System.out.print("Enter two numbers to find their GCD: ");

 int number1 = input.nextInt();

 int number2 = input.nextInt();

 

 if(number1 > 0 && number2 > 0)

     System.out.println("GCD of " + number1 +" and " + number2 +" is: " + findGCD(number1, number2));

       else

           System.out.println("Invalid Input!");

}  

public static int findGCD(int number1, int number2) {

    if(number2 == 0){

        return number1;

    }

return findGCD(number2, number1 % number2);

}

}

Explanation:

To be able to find GCD, we need to factorize the numbers and multiply common factors.

- <u>Inside the function:</u>

- Recursively divide <em>number1</em> by <em>number2</em> until <em>number2</em> is equal to zero.

- Return <em>number1</em>  when the <em>number2</em> is equal to zero. That means we found all the divisors of <em>number1</em>

- <u>Inside the main:</u>

- Ask user to input numbers

- Check if both numbers are greater than zero

- If they satisfy the condition, call the method and print the result.

You might be interested in
How to tell if screen or screen protector is cracked?
beks73 [17]
You will feel the screen protector crack
6 0
3 years ago
Read 2 more answers
Alternating Current or AC is better for use in ___________, while DC direct current is needed in _________ .
PIT_PIT [208]
<span>C electric power transmisson and electronics</span>
6 0
2 years ago
Read 2 more answers
If a wire has insulation that allows it to operate in a temperature of up to 194 degrees Fahrenheit, what temperature will the w
zzz [600]
(194°F-32)×5/9
= 90°C
therefore the answer is 90degrees Celcius
6 0
3 years ago
Who do we make games for?(single term)
Ket [755]

Answer:

Gamers

Explanation:

5 0
3 years ago
Read 2 more answers
What type of compensation does a travel agent receive from suppliers?
insens350 [35]

The travel agents receive compensation from suppliers such as waiting time compensation, night ride compensation, and cancellation compensation.

<u>Explanation</u>:

  • The travel agents from ola, uber and other companies usually receive compensation such as 10 percent commission of booking fees.  Usually, if the customer cancels the ride the travel agent will receive compensation for that ride.  They also receive time compensation for their work.
  • For long rides, the travel agents will receive extra compensation for that. Because the distance for that ride will be long. So they will receive these types of compensations from suppliers.    

6 0
3 years ago
Read 2 more answers
Other questions:
  • Select all of the uses of presentation software in the workplace.
    8·1 answer
  • Businesses have taken advantage of many of the smart phone features to promote their business. TRUE OR FALSE
    5·2 answers
  • Tiffany is an instructor at a college that is run on student tuition and not state taxes. Which statement best describes her emp
    6·2 answers
  • _____ refers to unsolicited commercial emails, usually sent to a large number of people with little regard to the users interest
    14·1 answer
  • Tom is the aerobics coordinator at a fitness center. He needs a more efficient way for his instructors to share information. Cla
    13·2 answers
  • Hurry answerrrrrrr pleaseee
    11·2 answers
  • Which of the following might an interior designer in the retail industry specialize in?
    9·1 answer
  • Using ________ as a promotion method will bring return visitors to your site.
    8·1 answer
  • Site at least 3 articles of impact of internet that affect in our daily lives.
    15·1 answer
  • Implement a simplified version of a crypto broker platform. Initially, there is an array of users, with each user depositing onl
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!