Division without / operator
A couple of comments first

It would be better to let your divide method should return an int, not do the output to System.out itself. Do the output in main like this:

public static void main(String[] args) {
    System.out.println(divide(-4,-10));
}


The variables N and D are short and don't follow the Java naming conventions. Parameter names should start with a lowercase letter and use camelCase. I would recommend calling them numerator and denominator.

If denominator == 0 is a quite exceptional case, I would recommend throwing an ArithmeticException stating that it was caused by division by zero.

You treat more special cases than you need to. I don't think you need to handle either numerator == denominator or numerator == 0 as a special case. It should be possible to handle that using the normal logic for division.

If you were doing divisions by a power of 2 (2, 4, 8, 16, etc.) you could use right shift numerator &gt;&gt; 1, numerator &gt;&gt; 2 etc. However, your code should support more than just those cases which makes things more difficult.

In the end, you are trying to re-implement division by using repetitive subtraction. It will be slow, no matter what you do. If you want to be possibly somewhat faster for bigger numbers, or want to try another approach (I can't promise you it will be faster, but I believe that for big enough numbers it will be significantly faster), you could try to implement division by using one of the good old "pen and paper" ways. Think about the division 303364 / 596. Try to solve that by hand! and think about what it is that you are doing. (Hint: Also think about how you do multiplications by hand, how would you solve 583 * 42 ?)

However, in reality though, the fastest solution is to use the / operator in Java, but that wouldn't be a challenge now, would it? So I guess that's out of the question :)