Java program that reads an integer and prints how many digits the number has
###### Posted by Samath
Last Updated: February 11, 2021

Write a Java program that reads an integer and prints how many digits the number has, by checking whether the number is ≥ 10, ≥ 100, and so on. (Assume that all integers are less than ten billion.) If the number is negative, first multiply it by –1.

Code:

```import java.util.Scanner;

public class Main
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);

System.out.print("Please Enter Number: ");
long inp = input.nextInt();
input.close();

int result = 1;
if (inp < 0) inp *= -1;
if (inp >= 10 && inp < 100)
{
result = 2;
}
else if (inp >= 100 && inp < 1000)
{
result = 3;
}
else if (inp >= 1000 && inp < 10000)
{
result = 4;
}
else if (inp >= 10000 && inp< 100000)
{
result = 5;
}
else if (inp >= 100000 && inp < 1000000)
{
result = 6;
}
else if (inp >= 1000000 && inp < 10000000)
{
result = 7;
}
else if (inp >= 10000000 && inp < 100000000)
{
result = 8;
}
else if (inp >= 100000000 && inp < 1000000000)
{
result = 9;
}
else if (inp >= 1000000000 && inp < 1000000000)
{
result = 10;
}
else
{
System.out.println("Number is greater than 10 billion.");
}
System.out.printf("Result: %d", result);
}
}
```
###### C++ Summing the digits in an integer
Samath | Jan 06, 2021
###### Recursive function that find the sum of digits in a integer using C++
Samath | Dec 24, 2014
###### Summing the Digits in an Integer using Python
Samath | Mar 02, 2015
###### C program that prompts the user for a positive integer and then computes the sum of all the digits of the number
Samath | May 04, 2016
###### Java program that read a five-digit positive integer and breaks it into a sequence of individual digits
Samath | Feb 10, 2021
###### SQL Display two digits after decimal point
SceDev | Feb 08, 2024
###### Python program that test if integer values can form a triangle
Samath | Nov 06, 2014
###### Java program that uses a loop to compute the sum of all odd digits of an input. (For example, if the input is 32677, the sum would be 3 + 7 + 7 = 17.)
Samath | Apr 03, 2022
###### C program that receives an integer number and determines if it is a prime number
Samath | Jun 01, 2015
###### Convert Integer to Roman Numeral using C#
Samath | Jan 20, 2024
###### C program that takes a non- negative integer number as input and prints its binary representation
Samath | Jan 01, 2017
###### C++ Convert an Integer to Roman Numeral
Samath | Jan 20, 2024
###### Java program that reads an integer and prints if it's positive or negative
Samath | Feb 11, 2021
###### C++ program that prompts the user to input a decimal number and outputs the number rounded to the nearest integer
Samath | Apr 06, 2022