MCPcopy Index your code
hub / github.com/careercup/ctci / negate

Method negate

java/Chapter 7/Question7_4/Question.java:5–13  ·  view source on GitHub ↗
(int a)

Source from the content-addressed store, hash-verified

3public class Question {
4 /* Flip a positive sign to negative, or a negative sign to pos */
5 public static int negate(int a) {
6 int neg = 0;
7 int d = a < 0 ? 1 : -1;
8 while (a != 0) {
9 neg += d;
10 a += d;
11 }
12 return neg;
13 }
14
15 /* Subtract two numbers by negating b and adding them */
16 public static int minus(int a, int b) {

Callers 4

minusMethod · 0.95
absMethod · 0.95
multiplyMethod · 0.95
divideMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected