Take this case for example:
num=8485
System.out.print((char)(‘0’+9 - num.charAt(0) +‘0’));
what is the use of ‘0’ here?
Take this case for example:
num=8485
System.out.print((char)(‘0’+9 - num.charAt(0) +‘0’));
what is the use of ‘0’ here?
@shubhij hi, see ‘0’ is character in java which has ASCII value of 48, now it has quite a cool use!
Suppose you have a string say str = “45”
So suppose you extract each character, you can convert each character to an integer by:-
‘5’ - ‘0’ this will give you an integer 5 because it is subtracting the ascii values of ‘5’ and ‘0’ characters.
So I give you a small task that is add the values of each character of some number string.
If you have any doubt feel free to ask, else mark the doubt resolved.
Happy coding!