what actually the 2nd requirement asks us to do. it doesn't specifically says that if integer is negative throw exception. it says if lines can't be converted to positive throw exception.
package com.codegym.task.task14.task1420;
/*
GCD
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int a=Integer.parseInt(reader.readLine());
int b=Integer.parseInt(reader.readLine());
System.out.println(gcd(a,b));
}
public static int gcd(int a, int b){
if(a==0 || b==0)return 0;
else if(a<0 || b<0)
throw new IllegalArgumentException();
else if(a==b)return a;
else if(a>b)return gcd(a-b,b);
return gcd(a,b-a);
}
}