60 36 Exception in thread "main" java.lang.ArithmeticException: / by zero at GCD.main(GCD.java:13)

import java.util.*;
public class GCD {

public static void main(String[] args) {
	 
	
	Scanner sc=new Scanner(System.in);
	
	int divident =sc.nextInt();
	int divisor =sc.nextInt();
	int rem;
	
	while(divident/divisor != 0)
	{
		  rem=divident % divisor;
		  divident=divisor;
		  divisor=rem;
	}
	
	System.out.println(divisor);
}

}

it should be while(divisor != 0)

divident-60
divisor-36
0
This is the answer after doing -while(divisor!=0)

Arithmetic exceptions are raised during run time by Java Virtual Machine when you try to perform any arithmetic operation which is not possible in mathematics. In most cases, when a number is divided by zero, the result is undefined and that is when this ArithmeticException occurs.

You can handle Java ArithmeticException in the following methods:

  • You should make sure the divisor isn’t zero (0) before attempting any division.
  • You can handle the ArithmeticException using Java try and catch blocks.