学习Java时,国内老师往往使用gw, sw, bw等汉语拼音缩写来代替,但是身为事事追求尽善尽美和professional范的准工程师们,我们怎么能满足于这么low的写法呢!
首先我上网查询了下个位数,十位数等英文的表达,得到的答案如下:
In the number 386 for example, the number 6 is the "unit's digit" (in the "unit's place"), 8 is the "ten's digit" (in the "ten's place"), and 3 is the "hundred's digit."
所以呢,我们可以知道,标准的说法就是:
个位 unit's digit;
十位 ten's digit;
百位 hundred's digit;
千位 thousand's digit;
万位 ten thousand's digit;
但是这样让我们怎么起变量名啊,变量名里面我们是不能使用单引号( ' )的。回忆下,老师说了,Java里面只能用大小写字母,数字,下划线和$,而且开头不能为数字。
因此,一个比较折中,而且简洁的办法是说,我们可以按照从右到左第几位数来给变量命名,这样不仅直白,而且在有类似身份证号,银行卡号等十几位数字的时候新变量命名的可扩展性很好。(写程序一定要有容错性和可扩展性)
个位 dig_1;
十位 dig_2;
百位 dig_3;
千位 dig_4;
万位 dig_5;
代码示范
联系客服