Make a java program called Numbers.java with the following methods:
gcd(int,int) - determines the greatest common divisor of the two
numbers.
Ex. gcd(210,40) is 10
lcd(int,int) - determines the least common divisor of the two
numbers.
Ex. lcd(210,40) is 2
max(int,int) - determines the higher value of the two
numbers.
Ex. lcd(210,40) is 210
min(int,int) - determines the lower value of the two
numbers.
Ex. lcd(210,40) is 40
sum(int,int) - returns the sum of the two numbers. Ex sum(210,40) is 250
main() - lets the user input two numbers and output the gcd , lc , max , min and sum
import java.util.Scanner;
public class Numbers1 {
public static int gcd(int a, int b){
if (b != 0)
return gcd(b, a%b);
else
return a;
}
public static int lcd(int a, int b){
for(int i = 2;i<=a && i<=b; i++){
if(a%i==0 && b%i==0){
return i;
}
}
return 1;
}
public static int max(int a, int b){
if(a>b){
return a;
}
else{
return b;
}
}
public static int min(int a, int b){
if(a<b){
return a;
}
else{
return b;
}
}
public static int sum(int a, int b){
return a+b;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x, y;
System.out.println("Enter an integer: ");
x = sc.nextInt();
System.out.println("Enter another integer: ");
y = sc.nextInt();
System.out.println("GCD: "+gcd(x,y));
System.out.println("LCD: "+lcd(x,y));
System.out.println("MAX: "+max(x,y));
System.out.println("MIN: "+min(x,y));
System.out.println("SUM: "+sum(x,y));
}
}

Make a java program called Numbers.java with the following methods: gcd(int,int) - determines the greatest common...
Consider the problem of finding the Greatest Common Divisor (GCD) of two positive integers a and b. It can be mathematically proved that if b<=a GCD(a, b) = b, if (a mod b) = 0; GCD(a, b) = GCD(b, a mod b), if (a mod b) != 0. Write a recursive function called GCD with signature “public static int GCD(int a, int b)” that returns the greatest common divisor of two positive integers a and b with b <= a....
I want the code in C++ The greatest common divisor (GCD) of two integers is the largest integer that evenly divides each of the numbers. Write a function called GCD that has a void return type, and accepts 3 parameters (first two by value, third by reference). The function should find the greatest common divisor of the first two numbers, and have the result as its OUTGOING value. Write a main function that asks the users for two integers, and...
PYTHON In mathematics, the Greatest Common Divisor (GCD) of two integers is the largest positive integer that divides the two numbers without a remainder. For example, the GCD of 8 and 12 is 4. Steps to calculate the GCD of two positive integers a,b using the Binary method is given below: Input: a, b integers If a<=0 or b<=0, then Return 0 Else, d = 0 while a and b are both even do a = a/2 b = b/2...
I need java code for the following problem.
Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...
C++ I do not understand this problem.
14THE GREATEST COMMON DENOMINATOR PROBLEM Write a function named god() that accepts two integers as input parameters and returns the greatest common divisor of the two numbers. The greatest common divisor (GCD) of two integers, a and b, is the largest integer that is a factor of both a and b. The GCD of any number and 1 is 1, and the GCD of any number and o is that number. One efficient...
Design and implement a Java program (name it ArrayMethods), that defines 4 methods as follows: int arrayMax (int [ ] arr) determines and returns the maximum value within an array int arrayMin (int [ ] arr) determines and returns the minimum value within an array void arraySquared (int [] arr) changes every value within the array to value2 void arrayReverse (int [ ] arr) reverses the array (for example: 7 8 12 becomes 2 18 7) Test your methods by...
Use R language to program
Problem 1: Greatest Common Divisor (GCD) Please write two functions, g edi ) and gcdr , which both take two integers a, b and calculates their greatest common divisor (GCD) using the Euclidean algorithm gcdi () should do so using iteration while gcdr () should use recursion. Then write a third function, gcd(), which takes two integers a, band an optional third argument nethod which takes a charater string containing either "iterative" or "recursive", with...
Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: o Write a method called cubeIt that accepts one integer parameter and returns the value raised to the third power as an integer. 2. Write a method called randomInRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. o Write a method called larger that accepts two double parameters and...
coding in c programming
Functions & Arrays Q1) The greatest common divisor (GCD) of two Integers (of which at least one is nonzero) is the largest positive integer that divides the numbers. Write a C function ged that accepts two integers and returns 1 if both the integers are zero, otherwise it returns their GCD. Write a C program (that includes the function ged) which accepts two integers and prints their GCD. Sample output: Enter two integers: 0 0 At...
Write a java recursive program to calculate the greatest common divisor of two integer numbers. The program asks user to type two numbers a and b(suppose a>b). If b is 0, return a; else recursively call the method with two smaller parameters, one is b, the second is a mod b.