Не могу понять почему не работает. Если вводятся отрицательные числа, или строки, в консоли выскакивают исключения, но валидатор все равно не пускает. ЗЫ Пробовал int a = Math.abs(Integer.parseInt(s1)); int b = Math.abs(Integer.parseInt(s2)); результат тот же. =(
package com.javarush.task.task14.task1420;
import java.io.*;
import java.text.*;
/*
НОД
*/
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();
try {
int a = Math.abs(Integer.parseInt(s1));
int b = Math.abs(Integer.parseInt(s2));
int max = 0;
if (a <= 0 || b <= 0) throw new Exception();
if (a%b == 0)
max = b;
if (b%a == 0)
max = a;
for (int i = 1;;i++) {
if (a%i == a || b%i == b) break;
if (a%i == 0 && b%i == 0)
max = i;
}
System.out.println(max);
}
catch (NumberFormatException e) {
e.printStackTrace();
}
}
}