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
What is a location where the embedded multimedia terminal is connected to both outside and inside wiring​
anygoal [31]

Answer:

The answer to this question is "The main closet or telecommunications closet".

Explanation:

A multimedia terminal or multimedia terminal adapter (MTA) is also known as a Landline modem that operates just like a wireless router, but in terms of high-speed Internet, an MTA can provide Home Phone service only.

  • In the case of a significant power failure, MTAs have only a backup battery that will fuel the MTA for many hours.
  • This device is used to connect to a main or telecommunications closet.

4 0
3 years ago
In this lesson you wrote code to make the turtle draw squares. Briefly describe how the code for
ale4655 [162]

Explanation:

that programming language you must use?

3 0
3 years ago
What does the % find
Sever21 [200]

Answer:

The FIND function returns the position (as a number) of one text string inside another. If there is more than one occurrence of the search string, FIND returns the position of the first occurrence. FIND does not support wildcards, and is always case-sensitive.

Explanation:

4 0
2 years ago
John is an entrepreneur who plans to enter a franchise contract with a hotel business. Which of these is an advantage that John
ladessa [460]

The answer is C:

In most Franchise businesses, the franchisor provides ongoing guidance and support, and a developed way of doing business. In addition, they offer a higher rate of success as compared to start-up businesses and you may find it easier to secure finances for a franchise. You will get all the benefits that are attached with big businesses for a small business ownership.

3 0
3 years ago
Read 2 more answers
Why is it important to write something in the subject line of emails?
marin [14]
So the person can know what you want and it helps keep better track of emails and subject matters
8 0
3 years ago
Read 2 more answers
Other questions:
  • Question 1(Multiple Choice Worth 2 points)<br> Which of the following is true of a good photograph?
    10·2 answers
  • Henrietta, the owner of a very successful hotel chain in the Southeast, is exploring the possibility of expanding the chain into
    15·1 answer
  • MICR is an input or output devices
    5·1 answer
  • A company has critical systems that are hosted on an end-of-life OS. To maintain operations and mitigate potential vulnerabiliti
    14·1 answer
  • Is the Internet dangerous?
    10·2 answers
  • A reference parameter differs from an output parameter in that a reference parameter ______________________ but an output parame
    5·1 answer
  • How to select the entire worksheet?
    6·1 answer
  • Which type of information could be displayed using this line graph?
    12·2 answers
  • Which type of software is used for marketing research as a way to find out about users' preferences?
    12·1 answer
  • Create a Python program that computes the cost of carpeting a room. Your program should prompt the user for the width and length
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!