10. Write a Java program to count number of digits in a number.
Static :-
class loop10
{
public static void main(String args[])
{
int i=1234,count=0;
while(i!=0)
{
count++;
i=i/10;
}
System.out.println("Count :- "+count);
}
}
Output :-
Dynamic:-
class loop10
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int i,count =0;
System.out.println(" Enter the number is :- ");
i=in.nextInt();
while(i>0)
{
count ++;
i=i/10;
}
System.out.println("Count :- "+count);
}
}
Output :-