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
frutty [35]
4 years ago
7

The greatest common divisor of integers x and y is the largest integer that evenly divides into both x and y. Write a recursive

method gcd that returns the greatest common divisor of x and y. The gcd of x and y is defined recursively as follows: If y is equal to 0 then gcd(x,y) is x; otherwise gcd(x,y) is gcd(y,x%y), where % is the remainder operator
Computers and Technology
1 answer:
Virty [35]4 years ago
4 0

Answer:this is made in java programing language

Program:

/**********************************************************

* The following GreatestCommonDivisor class demonstrates *

* a method called gcd. It reads two integers from the user*

* and displays the GCD of two integers. The method gcd *

* calculates and returns the GCD of two integers. *

**********************************************************/

// GreatestCommonDivisor class

import java.util.Scanner;

public class GreatestCommonDivisor

{

// start main main method

public static void main(String[] args)

{

// declare variables

int firstInteger;

int secondInteger;

int gcdOfTwoIntegers;

// create an object for Scanner class

Scanner input = new Scanner(System.in);

Prompt the user to enter the two positive integers.

// prompt the user to enter the first integer

System.out.print("Enter the first positive integer: ");

firstInteger = input.nextInt();

// prompt the user to enter the second integer

System.out.print("Enter the second positive integer: ");

secondInteger = input.nextInt();

Call the gcd method to get the greatest common divisor of two integers.

// call gcd method to get gcd of two integers

gcdOfTwoIntegers =

gcd(firstInteger, secondInteger);

Display the greatest common divisor of two integers.

// display the gcd of two integers

System.out.println("The GCD of " + firstInteger + " and " + secondInteger +

" is " + gcdOfTwoIntegers);

} // end of main method

The following gcd method accepts two integers as its parameters. It finds and returns the greatest common divisor of these integers recursively.

// gcd method implementation

public static int gcd(int x, int y)

{

// verify whether the value of y is zero or not

if(y == 0)

// return x if the value of y is zero

return x;

else

/* call gcd method recursively if the value of y is non-zero */

return gcd(y, x % y);

} // end of gcd method

} // end of GreatestCommonDivisor class

Explanation:

You might be interested in
Operating systems provide a measure of security by allowing users to access to those resources they've been cleared to use as we
Nikolay [14]

Answer:

True

Explanation:

5 0
4 years ago
Write a python coding to input ten random numerical vales to a list. And display the list. Use a loop structure to enter values.
Zarrin [17]

Answer:

000110011111000010010101001001

Explanation:

8 0
3 years ago
ffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffd
Aneli [31]

ffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsaffdsa

8 0
3 years ago
Read 2 more answers
When a method returns an array reference, you include ____ with the return type in the method header.
lisov135 [29]

Answer:

b. []

Explanation:

Arrays are represented using [] . When a method returns an array reference, the method header contains an entry of the type <data-type>[].

For example, a method test which returns a reference to integer array and takes no parameters is of the form:

int[] test();

Similarly a method list_chars which takes a String as an argument and returns an array of chars has the form:

char[] list_chars(String s);

8 0
3 years ago
Which of the following events would most likely produce an earthquake
o-na [289]

i'll answer your question if you tell us what the "following events" are

5 0
3 years ago
Other questions:
  • Website reputation is an important part of page quality (PQ) rating. Reputation can justify the Highest rating and the Lowest ra
    15·1 answer
  • The feedforward part of the conversation should do all of the following except __________.a.identify the toneb.introduce the pur
    11·1 answer
  • Plz help me of this answer<br><br><br>language:python​
    7·2 answers
  • Your mother wants to purchase a large hard drive for her computer and asks you to see what type of drive interface she has. Her
    13·1 answer
  • Finish the program by choosing the correct terms.
    7·2 answers
  • An analogue sensor has a bandwidth which extends from very low frequencies up to a maximum of 14.5 kHz. Using the Sampling Theor
    9·2 answers
  • WHAT IS A GOOD APP FOR REMOVING VIRUSES AND IT YOU DONT HAVE TO PAY MUCH FOR IT ????? PLEASE HELP ME
    8·2 answers
  • What is geospatial technology ??​
    5·2 answers
  • Who is the traitor of UA?<br><br>1 Karishma<br><br>2 Yuga Aoyama<br><br>3 Denki <br><br>4 Mineta
    6·1 answer
  • Which join is made with the following query?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!