Count Total Digits in a Number (Contest)

Count Total Digits in a Number easy Time Limit: 2 sec Memory Limit: 128000 kB

Problem Statement :

You are given a number n. You need to find the count of digits in n. Input The first line of input contains T denoting the number of test cases. Each testcase contains one line of input containing n. For Python, Language Just Completes the function.

Constraints: 1 ≤ T ≤ 100 1 ≤ n ≤ 108 Output For each testcase, in a newline, print the count of digits in n.

Example

Input: 2 1 99999

Output: 1 5

Explanation: Testcase 1: The number of digits in 1 is 1. Testcase 2: The number of digits in 99999 is 5

link:https://my.newtonschool.co/playground/code/1oypzu2duu3w/

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