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
You have just taken over management of a server on which the previous server administrator has set up several server components,
Arisa [49]

Answer:

d. Ensure file caching and flushing are enabled for all disk drives.

Explanation:

When the disk reading and writing is delayed and the server performance is also slow after taking over management of a server.Previously the server has several server components.So to increase the performance we should ensure caching of the file and make sure that the flushing is enabled for all disk drives.Hence the answer to this question is option d.

8 0
3 years ago
When you are printing handouts, which of these can you do? A. Save paper by placing more than one slide per page. B. Check the f
Bogdan [553]
I would say D because if u double up in paper u save more and if people have a copy they are more likely to be able to follow along.
6 0
3 years ago
Selena needs to insert a comment in a webpage's code to ensure that other web team members who work with the page code understan
ANTONII [103]

Answer:

<!-- Modified by selena ramirez - for html compliance -->

Explanation:

In HTML, <!-- .. --> tag is used to insert comments in the webpage code.

Comments written inside the tag is visible only on the code, and is not displayed in the browsers when the page is requested by the client computer.

<em>Comment tag</em> is useful when there is a lot of code and multiple developers are dealing with the same code.

Comments help developers understand what changed is made and why.

5 0
3 years ago
If you commit retail theft your drivers license will be ? A. Revoked, B. Suspended, C. Cancelled or D. Restricted
Likurg_2 [28]
B.suspended because revoked only happens when it's a felony or reckless,and not cancellations because it would have to be false information.
3 0
3 years ago
Read 2 more answers
Write a program that, given an integer, sums all the numbers from 1 through that integer (both inclusive). Do not include in you
fgiga [73]

Answer:

let n = 10;

let sum = 0;

for(i=1; i<=n; i++) {

if ((i%5) && (i%7)) {

 sum += i;

}

}

console.log(`Sum 1..${n} excluding 5 and 7 multiples is ${sum}`);

Explanation:

This is in javascript.

example output:

Sum 1..10 excluding 5 and 7 multiples is 33

5 0
3 years ago
Other questions:
  • In an era of widespread cultural change within the United States,
    11·1 answer
  • Ruby is creating a presentation. She wants each slide displayed at intervals of five seconds. Which feature in the presentation
    6·2 answers
  • Suppose that an engineer excitedly runs up to you and claims that they've implemented an algorithm that can sort n elements (e.g
    5·1 answer
  • Approximately what percent of desktop PCs are used for work-related purposes?
    13·2 answers
  • A<br> is a reduced-size version of a graphic image used to help recognize and organize pictures.
    5·1 answer
  • Are all tps dashboards
    15·1 answer
  • Joe wants to use pictures from the Internet in a word processing program. Which is the most important aspect that Joe should con
    8·2 answers
  • Many networks are set up using a hierarchical architecture to create a "backbone" network. In this system, several connected rou
    12·1 answer
  • When a binary tree is full to its next to last level and its leaves on the last level are filled from left to right the tree is
    14·1 answer
  • The base position for your fingers to be placed on a keyboard is called<br> 2 point
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!