mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-25 05:22:39 +08:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class FloydTriangle {
|
||||
|
||||
class FloydTriangle {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
System.out.println("Enter the number of rows which you want in your Floyd Triangle: ");
|
||||
|
@ -1,15 +1,30 @@
|
||||
//Oskar Enmalm 3/10/17
|
||||
//This is Euclid's algorithm which is used to find the greatest common denominator
|
||||
//Overide function name gcd
|
||||
|
||||
public class GCD{
|
||||
|
||||
public static int gcd(int a, int b) {
|
||||
|
||||
int r = a % b;
|
||||
while (r != 0) {
|
||||
b = r;
|
||||
r = b % r;
|
||||
public static int gcd(int num1, int num2) {
|
||||
|
||||
int gcdValue = num1 % num2;
|
||||
while (gcdValue != 0) {
|
||||
num2 = gcdValue;
|
||||
gcdValue = num2 % gcdValue;
|
||||
}
|
||||
return b;
|
||||
return num2;
|
||||
}
|
||||
public static int gcd(int[] number) {
|
||||
int result = number[0];
|
||||
for(int i = 1; i < number.length; i++)
|
||||
//call gcd function (input two value)
|
||||
result = gcd(result, number[i]);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
int[] myIntArray = {4,16,32};
|
||||
//call gcd function (input array)
|
||||
System.out.println(gcd(myIntArray));
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,8 @@
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.text.*;
|
||||
import java.math.*;
|
||||
import java.util.regex.*;
|
||||
|
||||
public class Solution {
|
||||
|
||||
|
Reference in New Issue
Block a user