When I run this, it works without any problems. But as soon as I do the validation I get "The program ran too long and was closed" . Any ideas?
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 br = new BufferedReader(new InputStreamReader(System.in));
int n1 = 0;
int n2 = 0;
try{
n1 = Integer.parseInt(br.readLine());
n2 = Integer.parseInt(br.readLine());
}catch (Exception e){
e.printStackTrace();
}
displayGgt(n1, n2);
}
private static void displayGgt(int n1, int n2) {
while (n2 != 0) {
if (n1 > n2) {
n1 = n1 - n2;
} else {
n2 = n2 - n1;
}
}
System.out.println(n1);;
}
}