an exception is thrown if my entered number is 0 or less, and the GCD is right for any values I put in.
Can anyone point out my mistake? thank you.
package com.codegym.task.task14.task1420;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/*
GCD
*/
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());
try {
if (a <= 0)throw new Exception();
if (b <= 0)throw new Exception();
}
catch (Exception e) {
//System.out.println(e);
}
int GCD = 1;
for (int i = 1; i < a&&i < b; i++) {
if (a%i == 0&&b%i == 0) {
GCD = i;
}
}
System.out.println(GCD);
}
}