исключение есть
делитель выводит
package com.javarush.task.task14.task1420;
/*
НОД
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String s1 = reader.readLine();
String s2 = reader.readLine();
int i1 = 0;
int i2 = 0;
ArrayList<Integer> nodlist = new ArrayList<>();
try {
i1 = Integer.parseInt(s1);
i2 = Integer.parseInt(s2);
if(i1<0)throw new Exception();
if (i2<0)throw new Exception();
int max = Math.max(i1, i2);
int min = Math.min(i1,i2);
int nod = min;
while (nod != 0){
nod = max % nod;
nodlist.add(nod);
max = min;
min = nod;
}
int index = nodlist.size();
System.out.println(nodlist.get(index-2));
}catch (Exception e){
System.out.println("Неверно введены данные!");
}
}
}