Java Program to Check if Line Passes Through the Origin

bookmark

class Main
{
    // Driver method
    public static void main(String args[])
    {
        //points are declared
        IntsPoint x1 = new IntsPoint(1,28);
        IntsPoint x2 = new IntsPoint(2,56);
        boolean a= x1.a * (x2.b - x1.b) == x1.b * (x2.a - x1.a);
        if(a==true)
            System.out.println("line is passing through origin ");
        else 
           System.out.println("line is  not passing through origin "); 
    }
    
     static class IntsPoint
    {
        int a,b;
        public IntsPoint(int a, int b) 
            {
                this.a = a;
                this.b = b;
            }
    }
   
}

 


Output:

line is passing through origin