Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AIRAT1/bb8082c4480ab52cbae1 to your computer and use it in GitHub Desktop.
Save AIRAT1/bb8082c4480ab52cbae1 to your computer and use it in GitHub Desktop.
package com.javarush.test.level14.lesson08.bonus02;
package com.javarush.test.level14.lesson08.bonus02;
/* НОД
Наибольший общий делитель (НОД).
Ввести с клавиатуры 2 целых положительных числа.
Вывести в консоль наибольший общий делитель.
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class Solution
{
public static void main(String[] args) throws Exception
{
ArrayList<Integer> list = new ArrayList<Integer>();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int zahl1 = Integer.parseInt(reader.readLine());
int zahl2 = Integer.parseInt(reader.readLine());
int mod = 1;
int min = 0;
int max = 2147483647;
boolean b = true;
while (true) {
if (zahl1 < 0 || zahl2 < 0) {
System.out.println("Zahle muesens groeser als null sein");
break;
}else if (zahl1 < zahl2) {
min = zahl1;
max = zahl2;
}else if (zahl2 < zahl1) {
min = zahl2;
max = zahl1;
}else {
mod = zahl1;
}
// System.out.println("min is " + min);
// System.out.println("max is " + max);
//break;
for (int i = min; i > 0; i--) {
if (min % i == 0) {
list.add(i);
}
}
for (int i : list) {
if (max % i == 0) {
mod = i;
break;
}
//System.out.println(i);
}
break;
}
System.out.println(mod);
}
}
@AIRAT1
Copy link
Author

AIRAT1 commented Aug 20, 2014

Die Aufgabe war gar nicht schwer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment