+ 1
Program java
write program that gets number and prints his number of digit. example 575. its 3.
3 Answers
+ 22
check it here
https://code.sololearn.com/cU9ZTNb0mnuI/?ref=app
import java.util.*;
public class Program
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int z=n;
int c_1=0;
while(z!=0)
{
c_1++;
z=z/10;
}
System.out.println("Num is:"+n);
System.out.println("Number of Digit:"+c_1);
}
}
+ 3
It even works for strings:
import java.util.Scanner;
public class Program {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.next();
System.out.println(str.length());
}
}