我需要帮助才能从字符串转换为 int,我已经搜索并没有找到任何可以帮助我解决这个特定问题的东西。
这就是我到目前为止所得到的......(代码下来)
- 卡必须是 6 位长(例如 123456) - 明白了
- 我已经隔离了卡号的每个数字(个,十,百......)
- 我使用字符串组合了卡片的前五位数字(从左侧开始)。
现在在组合前 5 个数字(例如 1+2+3+4+5=12345)后,我需要将这个数字修改为 7(12345%7)
但它不断给我下一个错误-
输入字符串的 java.lang.number.formatexception:五位数字:(在 java.lang.number.formatexception 中)
任何有关如何修复它的指南将不胜感激。谢谢。
if(creditCard<=99999||creditCard>=1000000)
System.out.println("Your credit card is not valid. You cannot buy the ticket");
else
{
ones = creditCard%10;
tens = (creditCard%100)/10;
hundreds = (creditCard%1000)/100;
thousands = (creditCard%10000)/1000;
tensOfThousands = (creditCard%100000)/10000;
hunOfThousands = (creditCard%1000000)/100000;
String fiveDigits = "" + hunOfThousands+tensOfThousands+thousands+hundreds+tens;
int firstFiveDigits = Integer.parseInt("fiveDigits");
int remainder = firstFiveDigits%7;
if(remainder==ones)
System.out.println("Your credit card is valid. Bon Voyage!");
else
System.out.println("Your credit card is not valid. You cannot buy the ticket");