Count Digits in a Number - Solution | Java Foundation Course | Lecture 17

preview_player
Показать описание
Question Name:
Count Digits in a Number

Question Link:

Question Statement:
1. You've to count the number of digits in a number.
2. Take as input "n", the number for which the digits has to be counted.
3. Print the digits in that number.
--------------------------------------------------------------------------------------------------------------------------------------------------------------

-----------------------------------------------------------------------------------------------------------------------------------------------------------------

Pepcoding has taken the initiative to provide counselling and learning resources to all curious, skillful and dedicated Indian coders. This video is part of the series to impart industry-level web development and programming skills in the community.

We also provide professional courses with live classes and placement opportunities.

DSA Level 1 and Level 2

We are also available on the following social media platforms: -

HAPPY PROGRAMMING!
Pep it up.....

Hashtags
Рекомендации по теме
Комментарии
Автор

Int n = sc.nextInt();
Int a=0; int num=n;
For(int i=0;i<n;i++){
Num=num/10;
a++;
If(num==0){
System.out.println(a);
Break;
}
}

Trading_Content
Автор

Sir Thanks a lot aapne itne hardwork ke saath playlist banayi hai ...!!❤❤ For DSA

arnavkukreti
Автор

Another way it can be done.

static int countDigitsInNumber(int n) {
String s = Integer.toString(n);
return s.trim().length();
}

muntasirmahmudsaif
Автор

If we pass num as
Then it will give 0 only how to deal with it

prabhurout
Автор

sir, when I enter number greater than 8 digits it''s throwing me an error,
I think then I have to handle it using BigInteger class, and that's why constraints are given.
nice videos, easy explanation, Thank you for free courses.
I remember your video with Umang(Get Saged Channel) where you say all content is free, it's matter of discipline.
I first solved it in editor and then came here for solution of BigInteger, but will implement it later, when I find it in series.

gdthegreat
Автор

Sir i have solved it by taking condition n>0 in while loop and it is giving right output .... is it wrong sir ?

RishabhSharma-tprs
Автор

What if number is starting from 0.
Eg :- 0118024
It will print from will not print 0

tejas
Автор

when we enter the no. (n= 0) it might give an error.

ujjwalsinghal
visit shbcf.ru