I can't figure what's wrong. My code works but the third step doesn't work. Can someone help me please?
package fr.codegym.task.task14.task1420;
/*
PGCD
*/
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 n1= Integer.parseInt(reader.readLine());
int n2= Integer.parseInt(reader.readLine());
if (n1<=0||n2<=0) throw new NumberFormatException();
for (int i=Math.max(n1,n2)/2;i>0;i--){
if (n1%i==0 && n2%i==0){
System.out.println(i);
break;
}
}
}
}