I'm writing a code in which in its main method I create an object. But I don't know how to call its constructor. here is my code:
//This class calculate the greatest common divisor of two number
import static java.lang.Math.min;
public class Calculate2
{
private int num1,num2;
public Calculate2(int num1 , int num2)
{
this.num1=num1;
this.num2=num2;
}
public static void main(String[] args)
{
Calculate2 gcd = new Calculate2();
gcd.GCD();
}
public void GCD()
{
int min_num;
int greatestcommondivisor=0;
min_num = min(num1,num2);
for(int commondivisor=1;commondivisor <= min_num;commondivisor++)
{
if(num1%commondivisor==0 && num2%commondivisor==0)
{
greatestcommondivisor=commondivisor;
}
commondivisor++;
}
System.out.println(greatestcommondivisor);
}//End of the method gcd
}//End of the class calculate2
how should I call the constructor?