+ 1

Program java

write program that gets number and prints his number of digit. example 575. its 3.

21st Nov 2017, 6:40 AM
Toren Shragai
Toren Shragai - avatar
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); } }
13th Dec 2017, 2:34 AM
ASIF BILAKHIYA
ASIF BILAKHIYA - avatar
19th Dec 2017, 10:28 PM
ASIF BILAKHIYA
ASIF BILAKHIYA - avatar
+ 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()); } }
21st Nov 2017, 7:35 AM
ChessMaster
ChessMaster - avatar