Все работает ответ выдает, при строках или 0 или отрицательных числах вылетает исключение и завершается с кодом 1
Что не так??? )))
package com.javarush.task.task14.task1420;
/*
НОД
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Введите 2 целых положительных цисла");
String str1 = br.readLine();
String str2 = br.readLine();
int count1 = Integer.parseInt(str1);
int count2 = Integer.parseInt(str2);
if (!isNumber(str1) || !isNumber(str2)) {
throw new Exception();
} else if (count1 <= 0 || count2 <= 0) {
throw new Exception();
}
br.close();
System.out.println(nod(count1, count2));
}
public static boolean isNumber(String vvod) {
try {
int i = Integer.parseInt(vvod);
} catch (NumberFormatException e) {
return false;
}
return true;
}
public static int nod (int count1, int count2) {
int min = 0;
if (count1 > count2) {
min = count2;
} else {
min = count1;
}
int nod = 1;
for (int a = 1; a < min; a++) {
if (count1 % a == 0 && count2 % a == 0) {
nod = a;
}
}
return nod;
}
}