Important alert: (current site time 5/28/2015 5:35:21 PM EDT) They're finally here! Check out our new 7 Source Code CDs!

# Convert Numers to Digits

Email
 Submitted on: 4/24/2012 10:23:39 AM By: AhmedNassar Level: Beginner User Rating: Unrated Compatibility: Java (JDK 1.4), Java (JDK 1.5) Views: 1533

Convert Number to separate digits: 123321 converted to 1 2 3 3 2 1 then you can use each digits individually.

code:
Can't Copy and Paste this?
 Terms of Agreement:    By using this code, you agree to the following terms...    You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.    You may link to this code from another website, but ONLY if it is not wrapped in a frame.  You will abide by any additional copyright restrictions which the author may have placed in the code or code's description. ``` //************************************** // Name: Convert Numers to Digits // Description:Convert Number to separate digits: 123321 converted to 1 2 3 3 2 1 then you can use each digits individually. // By: AhmedNassar // //This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=7018&lngWId=2//for details.//************************************** import java.lang.reflect.Array; import java.util.Scanner; public class DigitsToIntegers { public static void main ( String args[] ) { long num;// long number int arrCount; Scanner input = new Scanner (System.in); System.out.println("enter number "); num = input.nextLong();//input as a long arrCount = String.valueOf(num).length(); //count the length of the input System.out.println(arrCount); long arr[] = new long [arrCount]; for (int j = 0; j < arrCount; j++) { arr[j] = (long) (num/(Math.pow(10, (arrCount-j-1)))); num = (long) (num - (arr[j]*(Math.pow(10,(arrCount-j-1))))); System.out.print(arr[j]+" " ); } } } ```

Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)