Discussion Board
Go to the previous messageThere are no next messages
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
}
Post response

Go to the previous messageThere are no next messages
Current Thread Detail:
elements of an int      Pinto, Jessica L.      Mon Dec 3 2001 9:35 pm       
Re: elements of an int      Chen, Richard      Sun Dec 9 2001 9:37 am       

Back to previous screen