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
Suppose you have a program P and 90 percent of P can be parallelized, but 10 percent of P is inherently sequential and cannot be
EleoNora [17]

Answer:

Means no matter how many processors you use, speed up never increase from 10 times.

Explanation:

If a problem of size W has a serial component Ws,then performance using parallelism:

Using Amdahl's Law:

Tp = (W - Ws )/ N + Ws

Here, Ws = .1,

W - Ws = .9

Performance Tp = (.9 / N) + .1

---------------------------------------------------------

Speed Up = 1 / ( (.9 / N) + .1)

If N -> infinity, Speed Up <= 10

Means no matter how many processors you use, speed up never increase from 10 times.

5 0
2 years ago
What is the reason for taking care of design a good computer human interface ​
anygoal [31]

Answer:

computer is one of the part of our technology so that let's take care of it and improve so that we can used for better and sufficient ly not maybe now but maybe soon.

3 0
3 years ago
Read 2 more answers
(The Person, Student, Employee, Faculty, and Staff classes) Design a class named Person and its two subclasses named Student and
Mariulka [41]

Answer:

Explanation:

The following code is written in Java and creates all the classes as requested with their variables, and methods. Each extending to the Person class if needed. Due to technical difficulties I have attached the code as a txt file below, as well as a picture with the test output of calling the Staff class.

3 0
3 years ago
• R7.9 Write enhanced for loops for the following tasks.
alexdok [17]

Answer:

a is the correct answer

Explanation:

correct me if I'm wrong hope it's help thanks

3 0
3 years ago
Which commas is used to combine two or more cells together into one cell
AURORKA [14]
The command is Merge & Center
This command could be easily found in the toolbar of your excel.
If you execute this command in two different cells, those cells will be merged into one larger cell and the content in that cells will be placed exactly in the middle of the combined cell (measures according to combined cells' length)
5 0
3 years ago
Other questions:
  • You will start by doing a bit of research on viewfinders and LCD displays on digital cameras. After you feel that you have an un
    10·1 answer
  • Want is the assignmment
    8·1 answer
  • How did mark watney survive the accident
    9·1 answer
  • If the physical memory size is doubled without changing any of its other parameters, the number of entries in the page table
    5·1 answer
  • #11. Write a program that prompts the user to input a four-digit positive integer. The program then outputs the digits of the nu
    6·1 answer
  • Choose the risks from the options below to presenting yourself differently online than offline?
    12·1 answer
  • Random access memory is the portion of a computer's primary storage that does not lose its contents when one switches off the po
    6·2 answers
  • Maria works for MegaCorp, a large privately owned company specializing in sales of ball bearings. MegaCorp introduces filtering
    15·1 answer
  • Which type of cloud computing offers easily accessible software and applications on the machines?
    7·1 answer
  • Write at least and explain four types of escape sequences and create an example in an IDE which consist of the mentioned escape
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!