java问题

Page content

[TOC]

学习过程中遇到的一些技术问题。

Q. What is the result of division and remainder for negative integers?

A. The quotient a/b rounds toward 0; the remainder a % b is defined such that (a / b) * b + a % b is always equal to a. For example, -14/3 and 14/-3 are both -4, but -14 % 3 is -2 and 14 % -3 is 2

Q. Some Java programmers use int a[] instead of int[] a to declare arrays. What’s the difference?

A. In Java, both are legal and equivalent. The former is how arrays are declared in C. The latter is the preferred style in Java since the type of the variable int[] more clearly indicates that it is an array of integers.

java中使用int[]的形式声明数组。