How would we check whether that integer has the number 5 in it, so we can find the sum of all integers 1 through 100 excluding those with 5's in them.
So for example, 5, 52, 57, 85, are not eligible integers for our sum. Is there a built in method i can use ?
Stuart A. Burkett wrote:An alternative approach is to convert the number to a String and then check if the String contains a 5. That will work for any range of values.
I was thinking the same, then you can just check the substring values and if they == x, then put them into respective variables.
I hope you are not using == because it does not work. You have been given three different suggestions; all can be got to work. If you are using substrings, go through the String class and its methods and you will probably find something useful to ease your task.
Steve Alpine wrote: . . . check the substring values and if they == x, then put them into respective variables.
And welcome to the Ranch