How can i implement “intersection” method using java by recieve 2 integer parameters and return integer intersection point.
If what you want is a function that takes two 'line' objects and returns a coordinate where they intersect, i suggest looking at the formula here
http://en.wikipedia.org/wiki/Line-line_intersection
and doing
func(line a, lineb)
{
x1 = a.coord1.x;
y1 = a.coord1.y;
x2 = a.coord2.x;
y2 = a.coord2.y;
//do math and code here
return line(coord(x1new,y1new),coord(x2new,y2new));
}
If this isn't what you wanted, please refer to Ido's comment :p
If you want to be really lazy why don't you just use the line2d library. http://download.oracle.com/javase/1.4.2/docs/api/java/awt/geom/Line2D.html It can find the intersect and many other things that have to do with a 2d line already built in.
As far as I can see, if you use two integer parameters, all you really need to do is average the two numbers, and that's the midpoint (intersection, I guess?)
int intersect(int a, int b) {
return ((a + b) / 2);
}
Otherwise, if you are looking for bitwise intersection, you would used the bitwise-AND operator - &. Here's an example:
int intersect(int a, int b) {
return (a & b);
}