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
Consider the following code segment:
Leni [432]

The code segment is an illustration of loops and arrays

<h3>What is a loop?</h3>

A loop is a program statement used to perform repetitive operations

<h3>What is an array?</h3>

An array is a variable used to hold multiple values

<h3>How to analyze the program?</h3>

The loop of the program adds the index 0 elements of the first and the second row of the 2-dimensional array.

From the program, the numbers to add are 1 and 100

The sum of 1 and 100 is 101

Hence, 101 will be displayed when the code segment is executed

Read more about code segments at:

brainly.com/question/26683418

7 0
2 years ago
What were the results of Dr.bjork's experiment
Mademuasel [1]

Answer:

Studying in different rooms seemed to improve a persons memory

8 0
2 years ago
Write a statement that reads 5 successive integers into these variables that have already been declared: x1, x2, x3, x4, x5. The
prisoha [69]

Answer:

Following are the statement in C++ language :

#include <iomanip> // header file  

using namespace std; // namespace

int main() // main method  

{

   int x1,x2,x3,x4,x5; // variable declaration

cout<<" Enter the 5 sucessive integer:";

cin>>x1>>x2>>x3>>x4>> x5; // taking 5 input from user

cout<<right;

// prints each  of  its own line and form a right-justified  

cout<<setw(5)<< x1 << "\n" << setw(5) << x2 << "\n" <<setw(5) << x3 << "\n" << setw(5) << x4 << "\n" << setw(5) << x5 << "\n";

return(0);    

}

Output:

Enter the 5 sucessive integer: 45

23

445

6

8

 

  45

  23

 445

   6

   8

Explanation:

Description of program is given below  

  • Declared a 5 integer value x1,x2,x3,x4,x5 respectively.
  • Read the 5 integer value from user by using cin funtion.
  • Finally Print these 5 value in its own line and form a right-justified by using setw() function on it
5 0
3 years ago
Write the CSS for an id with the following attributes: i. float to the left of the page. ii. light tan background. iii. Verdana
miss Akunina [59]

Answer:

We create a block div with an id="block" and we make the css code

Explanation:

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>bloque</title>

<link href="bloque.css" rel="stylesheet" type="text/css">  

</head>

<body>

<!--we create the div with the id="block" and a text "hello world"-->

<div id="block"> hello world </div>

 

</body>

</html>

/* CSS Document */

/* we create the CSS file, then with the same id="block" we're programming in the CSS code*/

#block{

background-color: #ECDEC9;

padding: 20px;

float: left;

font-size: 50px;

font-family: "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans",     "DejaVu Sans", "Verdana", "sans-serif";

}

4 0
4 years ago
In a Windows environment, __________ is a powerful tool that enables security administrators to share user and group definitions
spayn [35]

Answer:

Active Directory

Explanation:

Active Directory (AD) is a Microsoft product that consists of several services that run on Windows Server to manage permissions and access to networked resources.

Active Directory categorizes objects by name and attributes. For example, the name of a user might include the name string, along with information associated with the user, such as passwords and Secure Shell (SSH) keys.

7 0
3 years ago
Other questions:
  • If you receive an increase in pay, how will that affect your payroll deductions?
    8·1 answer
  • What key combination in excel takes you back to the first cell
    7·1 answer
  • I am doing Microsoft Excel and I have do formulas, Can some please explain to me how do them?
    14·1 answer
  • Which unique address is a 128-bit address written in hexadecimal?
    13·1 answer
  • What component of a processor handles all logical comparisons and calculations inside the processor?
    9·1 answer
  • Suppose that the following elements are added in the specified order to an empty binary search tree: Lisa, Bart, Marge, Homer, M
    5·1 answer
  • Write a method intersect that accepts two sorted array lists of integers as parameters and returns a new list that contains only
    8·1 answer
  • Which of these conclusions supports the fact that Eclipse is categorized as an IDE?
    8·1 answer
  • If the bookstore sold 8 books for $66 at that rate how much was one book
    10·2 answers
  • What is the significance of the scientific method?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!