β Count Total Digits in a Number (Contest)
Count Total Digits in a Number easy Time Limit: 2 sec Memory Limit: 128000 kB
import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
public static void main (String[] args) {
// Your code here
Scanner sc=new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
String n =sc.next();
System.out.println(n.length());
}
}
}
//method 02
import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
public static void main (String[] args) {
// Your code here
Scanner sc=new Scanner(System.in);
int t= sc.nextInt();
while(t-->0){
int num=sc.nextInt();
int count=0;
while(num !=0){
count++;
num/=10;
}
System.out.println(count);
}
}
}
Last updated