![]() ![]() ![]() ![]() | Gcd1.java - Et Java program som implementerer Euclids GCD algoritme. | Lecture 3 - slide 19 : 39 Program 1 |
import oopcourse.util.Console; class Gcd1{ static int gcd(int input1, int input2){ int stor, lille, rest; stor = input1; lille = input2; while (lille > 0){ rest = stor % lille; stor = lille; lille = rest; } return stor; } public static void main(String args[]){ int i, j; i = Console.readInt("Indlæst det største af to positive tal"); j = Console.readInt("Indlæst det mindst af to positive tal"); System.out.println("GCD = " + gcd(i,j)); } } |