Ну что сделать то надо? Задача то работает :(
package com.javarush.task.task14.task1420;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
/*
НОД
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
try {
String q = in.readLine();
int a = Integer.parseInt(q);
String w = in.readLine();
int b = Integer.parseInt(w);
int c = Math.min(a, b);
int nod = 1;
for (int i = 1; i <= c; i++) {
if (a % i == 0 && b % i == 0) {
nod = i;
}
}
System.out.println(nod);
}
catch (NumberFormatException e){}
}
}