Discussion About GCD

This is Discussion thread about GCD

i donot know what is problem in my code can you please tell me what is going wrong

import java.util.*;
public class Main {
public static int gcd(int a,int b){
if(a==b)
return a;
if(a%b==0)
return b;
if(b%a==0)
return a;
if(a>b){
return gcd(a%b,b);
}
if(b>a)
return gcd(a,a%b);
return 0;
}
public static void main(String args[]) {
try{
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int b=sc.nextInt();
System.out.print(gcd(a,b));

}
catch(Exception e){System.out.print(e);}

}}

I don’t know why I am getting a segmentation fault error. It works fine on my laptop. Please help with it. Here is the Code:

#include
using namespace std;

long long find_gcd(long long a, long long b)
{
if(b==0)
return a;

return find_gcd(a%b, b);

}

int main() {

long long n1, n2;

cin>>n1>>n2;

long long ans = find_gcd(n1,n2);

cout<<ans;

return 0;

}

@nikhil015
return find_gcd(b,a%b);