Hi to all
I have a quick question. How can go through the integer to find if there is any specific number. For example my input would be 234446 (integer is of type long),and now I would like to check that integer and find how many 4's are in there and then display it.
Appreciate it
mauro21pl
10
Junior Poster in Training
Recommended Answers
Jump to PostYou can extract the no.'s digits by this method :
if n is user's input of int type thenwhile(n>0) { n=n/10; digit=n%10; if(digit==4) counter++; }
Then print the counter that contains the no. of 4's in your inputted number
Jump to Postthe method is easy :)
All 6 Replies
hinduengg
26
Junior Poster in Training
hinduengg
26
Junior Poster in Training
mauro21pl
10
Junior Poster in Training
TheGathering
12
Junior Poster
hinduengg
26
Junior Poster in Training
mauro21pl
10
Junior Poster in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.