?
一、/ 表示取商。
class="java plain" style="margin: 0px !important; padding: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; float: none !important; height: auto !important; line-height: 1.8em !important; overflow: visible !important; vertical-align: baseline !important; width: auto !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 12px !important; white-space: nowrap !important;">System.out.println(
3
/
5
)? =?
0
;
System.out.println(
2
/
5
)? =?
0
;
System.out.println(
4
/
5
)? =?
0
;
?
?
System.out.println(
6
/
5
)? =?
1
;
System.out.println(
7
/
5
)? =?
1
;
System.out.println(
8
/
5
)? =?
1
;
System.out.println(
11
/
5
)? =?
2
;
System.out.println(
12
/
5
)? =?
2
;
System.out.println(
13
/
5
)? =?
2
;
结果等于得到的整数(商的整数)
?
?
二、% 表示取模、也就是取余。
1 2 3 4 5System.out.println(
17
%
5
) =?
2
;
System.out.println(
16
%
5
) =?
1
;
System.out.println(
13
%
5
) =?
3
;
System.out.println(
8
%
5
) =?
3
;
System.out.println(
7
%
5
) =?
2
;
结果等于余数(剩余多少)
1 2 3System.out.println(
2
%
5
) =?
2
;
System.out.println(
7
%
8
) =?
7
;
System.out.println(
6
%
8
) =?
6
;
取余(取模)有个规律就是:左边小于右边,结果为左边,左边大于右边,看余数
?