偶的第一张信用卡

昨天偶的第一张信用卡终于到了,居然用了2个多月的时间。住宅电话当时是随便写了一个,结果晚上开通的时候杯具了,不得已只能让客服开通,还好,客户把我填写的固定电话告诉我了。

昨天晚上给自行车安上了买来的计速器,哇哈哈,这回可以统计每天骑车的最高速度了。

回头有时间贴个图上来。

 

*6.31(金融应用:信用卡号的合法性验证)信用卡号遵循某种模式。一个信用卡号必须是13到16位的整数。它的开头必须是: You rolled 5+6=11You win You rolled 1+2=3You lose You rolled 4+4=8point is 8You rolled 6+2=8You win You rolled 3+2=5point is 5You rolled 2+5=7You lose ● 4,指Visa卡 ● 5,指Master卡 ● 37,指American Express卡 ● 6,指Discover卡 1954年,IBM的Hans Luhn提出一种算法,用于验证信用卡号的有效性。这个算法在确定输入的卡号是否正确,或者这张信用卡是否被扫描仪正确扫描方面是非常有用的。遵循这个合法性检测可以生成所有的信用卡号,通常称之为Luhn检测或者Mod 10检测,可以如下描述(为了方便解释,假设卡号为4388576018402626): 1)从右到左对数位数字翻倍。如果对某个数字翻倍之后的结果是一个两位数,那么就将这两位加在一起得到一位数。 些 2)现在将第一步得到的所有一位数相加。 4+4+8+2+3+1+7+8=37 3)将卡号里从右到左奇数位上的所有数字相加。 6+6+0+8+0+7+8+3=38 4)将第二步和第三步得到的结果相加。 37+38=75 5)如果第四步得到的结果能被10整除,那么卡号是合法的;否则,卡号是不合法的。例如,号码4388576018402626是不合法的,但是号码4388576018410707是合法的。 编写程序,提示用户输入一个1ong型整数的信用卡号码,显示这个数字是合法的还是非法的。使用下面的方法设计程序: /**Return true if the card number is valid*1public static boolean isValid(1ong number)1**Get the result from Step 2*/public static int sumOfDoubleEvenPlace(1ong number)1**Return this number if it is a single digit,otherwise,*return the sum of the two digits*!public static int getDigit(int number)/**Return sum of odd-place digits in number*1public static int sumOfOddPlace(1ong number)1**Return true if the number d is a prefix for number*1public static boolean prefixMatched(1ong number,int d)/**Return the number of digits in d*/public static int getSize(1ong d)/**Return the first k number of digits from number.If the*number of digits in number is less than k,return number.*/public static 1ong getPrefix(1ong number,int k)
最新发布
10-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值