Java取模(求余)运算

        整数之间的取模求余运算很好求,但几乎没有遇到过对负数进行取模求余,直接看下面代码:

/**
 * 
 * @author Logic
 *
 */
public class Test {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println("-3%-2=" + -3%-2);
		System.out.println("3%-2=" + 3%-2);
		System.out.println("-3%2=" + -3%2);
	}
}
/**
 * Result
 * -3%-2=-1
 * 3%-2=1
 * -3%2=-1
 */

猜你喜欢

转载自logicluo.iteye.com/blog/2197591