Java to write a function that takes an integer, the integer output is a few number (Ziph)

@Java

Hello everyone, I'm Ziph!

Topic:
write a function that takes an integer, the output of the integer number is few

import java.util.Scanner;

public class TestInt {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.print("请输入一个整数:");
		long num = sc.nextLong();
		getNumLength(num);
	}
	public static void getNumLength(long num) {
		int count = 1;
		while(num >= 10) {
			count++;//如果满足条件就加1
			num /= 10;
		}
		System.out.println(count);
	}
}

The results:
Here Insert Picture Description
If you have questions, please leave a message reply!

Published 32 original articles · won praise 66 · views 10000 +

Guess you like

Origin blog.csdn.net/weixin_44170221/article/details/104272096