answersLogoWhite

0


Best Answer

There are different ways to do it.

One is to convert it to a String, then use the string manipulations methods to extract individual digits as strings. You can then convert them back to numbers.

Another is to do some calculations. For example, to get the last digit:

int i = 12345;

int lastdigit = i % 10;

//To get additional digits, divide by 10 and repeat:

i /= 10;

int lastdigit = i % 10;

In this case you can create a loop for this (repeating while i > 0), and copy the digits to an array.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you extract digits from an integer in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

In java How do you have a method take in an int value and return an int containing sum of the individual digits in the number using a recursive method?

Add the last digit plus the sum of all the previous digits. The base case is that if your integer only has a single digit, just return the value of this digit. You can extract the last digit by taking the remainder of a division by 10 (number % 10), and the remaining digits by doing an integer division by 10.


What are the constructor method of integer class?

If you mean Java, you can get the documentation for the Integer class (with an uppercase "I") here: http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Integer.html


How do you convert an int to object in java?

Java has auto-boxing introduced in Java 5 and converts ints to Integer objects as needed.Or you can explictly call Integer.valueOf(int) or new Integer(int) to return an Integer object with the value of the primitive int argument.Example:int i = 14; // i = 14Integer a = Integer.valueOf(i); // a = 14Integer b = new Integer(i); // b = 14or simplyInteger c = i;


Primitive java data types?

The primitive data types in Java are:int: integer value from -232 to 232floatdoublelong: integer value from -264 to 264byte: integer value from -128 to 128char: charactershort: integer value from -32768 to 32768boolean: true or false valueString (not actually a primitive data type)


What is the abbrevations for int?

"int" is the abbreviation for an integer data type. In Java an int is specifically a 32-bit signed integer.

Related questions

In java How do you have a method take in an int value and return an int containing sum of the individual digits in the number using a recursive method?

Add the last digit plus the sum of all the previous digits. The base case is that if your integer only has a single digit, just return the value of this digit. You can extract the last digit by taking the remainder of a division by 10 (number % 10), and the remaining digits by doing an integer division by 10.


What is the purpose of integer Java?

Within Java, an integer is an Object, which is converse to the "int", which is a primitive. In reality, this means that for an integer, a method can be called upon it, whereas with a primitive, this is not the case.


Can you do a boolean test on integer in java?

No


What is java's keyword for the integer data type?

"int" is the keyword for integer


What is the Java integer class used for?

The Java Integer class is there to help with math. It is very useful and very recommended. To learn more information about it, go to the official Java page.


Is 1212121212.... an integer?

If it ever ends, then it is.If there are no digits after the decimal point, it's an integer.


Is unsigned integer available in java?

No..Java Supports Signed positive and negative integers


Is 3.5 a odd integer?

It is not an integer, since it has digits after the decimal point.


What is a simple java code and explain what the code does?

int a;This simple Java statement declares an integer.


What is a int in java?

int is integer which means datatype


What are the constructor method of integer class?

If you mean Java, you can get the documentation for the Integer class (with an uppercase "I") here: http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Integer.html


How do you convert an int to object in java?

Java has auto-boxing introduced in Java 5 and converts ints to Integer objects as needed.Or you can explictly call Integer.valueOf(int) or new Integer(int) to return an Integer object with the value of the primitive int argument.Example:int i = 14; // i = 14Integer a = Integer.valueOf(i); // a = 14Integer b = new Integer(i); // b = 14or simplyInteger c = i;