Originally posted by mike cool:
hey i forgot to say
each element of the 2 arrays has only one digit
the 2 arrays have different sizes 30 and 40
and in the array where i will sum the 2 arrays each element must contain only one digit
it starts like this user will input string of numbers then this string will be added into char array then this char array wil be converted to int array , (this for each of the 2 arrays) then i need to compare them ...etc
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Regards,<br />Seb<br /> <br />SCJP 1.4
Regards,<br />Seb<br /> <br />SCJP 1.4
Regards,<br />Seb<br /> <br />SCJP 1.4
Originally posted by Seb Mathe:
Mike,
I don't understand why you don't want to use BigIntegers...
Originally posted by mike cool:
ok here is it step by step
1- creat two int array the size of each array must be 40
2- ask the user to input 2 strings (big numbers )
3- check each character of ths string if it's numeric characters
4- add each string in one int array
5-print out the sum of the 2 arrays
6-compare between the two arrays.
in step 1 i've created 2 int array with size 40 for each..
instep 4 i will read 2 strings from the user i will convert each character
of the string to int and add each digit to one elment of the int array
what i did is the following
1- read first string
2- add this string to char array using toCharArray();
3-check each character if it numeric charcter using isDigit(char c);
4-if it's ok i convert this char character to int using getNumericValue (char c);
5-add each character after i converted to one element of the first int array..
so it means that each elment in the int array will contain one digit..
6-do the same with the second string to the second int array.
now each element of each int array contain one digit (step 5)
1-how can i sum these 2 int array to new int array and this new int array
the new int array must contain in each elment only one digit
i can use %10 to do that but how can i add the remain to the next element is the sum is bigger than 9
2- to sum i need to read from right to left ,,do i need to start add to the last index?
3- the array size is 40 so if i use less elments the rest will contain zero's
how can i remove these zero's when i print the result
i have to use toString(); to print
i have to compare between the first int and the second int
not the array size but the number itself
are they equal ?
number 1 is greater than number 2
number (is the all digit in the array as one number)
Come on, mike, what happened to testing? What answer does this code give for 15 + 6 ? It looks to me that it will return 75. Is that correct?Originally posted by mike cool:
ok guys i solve to sum to int arrays without using BigInteger
here is the code
pls tell me if there is any thing wrong
Originally posted by Kym Thompson:
Come on, mike, what happened to testing? What answer does this code give for 15 + 6 ? It looks to me that it will return 75. Is that correct?
[ October 22, 2005: Message edited by: Kym Thompson ]
Come on, mike, what happened to testing? What answer does this code give for 15 + 6 ? It looks to me that it will return 75. Is that correct?
This code will only work correctly when array1 and array2 are both the same length
You should come up with some tests to check if your code is correct. For exmaple, what happens when you do this:
In particular, does the values in b here represent the number 24 or the number 42?
First of all, I think you should document your method. Just by looking at it, it is not clear that you expect both paramter arrays are the same length. I suggest you look into the Javadoc syntax.
I also have a question: What if you want to add three or more numbers together? You can easily create two int arrays for the first two numbers
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |