How can I get each digit of a 16 digit number and store each digit as a variable?
By : Michael Barzilovich
Date : March 29 2020, 07:55 AM
I wish this help you I need to write a Java program that validates credit card numbers, and to do that I need to preform operations on each individual digit. How can I get these digits, without using strings or arrays? code :
int number; (This would be your credit card number)
while (number > 0) {
System.out.println( number % 10);
number = number / 10;
}
|
If Statement to check last digit of number
By : user3365887
Date : March 29 2020, 07:55 AM
around this issue newNumber2 % 10 returns the last digit of newNumber2. a % b is the remainder of a divided by b - so this is the remainder of newNumber2 divided by 10, which happens to be the last digit. So you can use, for example: code :
if((newNumber2 % 10) == 1)
|
In phone number validation 9,10,14 digit numbers should be valid,if number start with + then any digit number should be
By : Ham
Date : March 29 2020, 07:55 AM
To fix this issue In my phone number validation i need to validate only 9,10,14 digit numbers and 11,12,13 numbers are not valid,if phone number start with + then any digit number should be valid.Any preg_match code available? please help. :( , You can try this : code :
preg_match('/(?=^\d{9,10}$)|(?=^\d{14}$)|(?=^\+\d*)/', '+123456789012', $matches);
print_r($matches);
|
Why this code error when entering a 4*x symbol number or more? Converting a 16 digit number into 10 digit number
By : user3474080
Date : March 29 2020, 07:55 AM
it helps some times i should start at 0, not -1. You haven't noticed it yet but your math is wrong for digits 0 through 9.
|
Java: Check if a number is a double digit or single-digit no if statement?
By : Udaykiran Arnipalli
Date : March 29 2020, 07:55 AM
around this issue I have homework to check if number is a double digit or a single-digit without using if statement. for your help! , Just set the value to the conditional:
|