Current Forum: Homework 6 Part 1 |
Date: Sun Dec 9 2001 9:37 am |
Author: Chen, Richard <richardc@andrew.cmu.edu> |
Subject: Re: elements of an int |
|
|
int DIGITS=2;//number of digits you have int[DIGITS] digits;//int array representing digits, L2R int num=10;//original integer to be deconstructed
//the Java2 API way String s=(new Integer(num)).toString(); for(int i=0;i<s.length();i++) { digits[i]=(int)s.charAt(i);//I forget if the casting results needs a +128 to be accurate }
//L2R way for(int i;i<DIGITS;i++) { digits[i]=original%10;//get 1 digit at a time num=-digits[i];//shave off the last digit //I can't figure out the forumla to eliminate the right-most digit } |
|